Home>

Operate the WEB application using Selenium VBA
thinking about.
I want to click on a search button
The code for that button
Search
Suppose.
Both this class = "A" and TEXT →'search'
Use (to avoid duplication with other elements when class = "A" and'search'are specified alone)
.FindElementByXPath (○○) .Click
I want to operate, but how should I fill in ○○?
I would appreciate it if you could teach me.
In addition, because we are beginners, there are misuses in the usage of terms.
If so, please forgive me.

  • Answer # 1

    Selenium has a FindElement 〇〇 method and a FindElements 〇〇 method.
    FindElement 〇〇 returns only the first element found,
    The FindElements 〇〇 method returns a collection of relevant elements.
    You can use FindElements to rotate the collection with For each and click when the corresponding text matches.

    Dim elm As Selenium.WebElement
    For Each elm In Driver.FindElementsByClass ("A")
    If elm.Text = "Search" Then
               elm.Click
               Exit For
           End If
    Next

  • Answer # 2

    As it isandso.

    "// span [@ class ='A' and text () ='search']"


    If the text contains spaces, use the appropriate function.

  • Answer # 3

    It may be extra care, but if you haven't considered it yet, try Cypress, which is made by Google.
    Selenium has various pitfalls, but Hama Cypress is very comfortable because it has been devised so as not to get hooked.