0

Need a resource not Selenium documentation or W3C website, all there is information about Java, Python codes. I need to see how to use FindElement(By) in VBA or

.FindElementByCss("li > div  > a=[href]").Click

The most useful site with examples I found is https://endtest.io/guides/blog/2020/07/31/a-practical-guide-for-finding-elements-with-selenium/

2
  • Does that expression not work for your use-case? What HTML are you trying to parse? Commented Aug 20, 2022 at 15:22
  • I edit code with all snippets Commented Aug 20, 2022 at 15:31

1 Answer 1

1

You were close enough. As an example for the following HTML:

<li>
    <div>
        <a href="https://stackoverflow.com">Stack Overflow</a>
    </div>
</li>

To identify the desired element you can use either of the following locator strategies:

  • Using FindElementByCss:

    .FindElementByCss("li > div > a[href]")
    
  • Using FindElementByCss (canonically):

    .FindElementByCss("li > div > a[href*='stackoverflow']")
    
  • Using FindElementByXPath (canonically):

    .FindElementByXPath("//li/div/a[@href=\"https://stackoverflow.com\"]")
    
Sign up to request clarification or add additional context in comments.

2 Comments

In my situation it is three same <li <div < a identical as in your example, for clicking the second one, I write code Xpath("section[2]/ul/li[2]/div/a"), But does not click when macros is compiling, when I put Wait(24000) then sometimes it clicks properly. It's strange. And Wait(24000) is long enough. I look to the webpage is loading in a 2 s, so why to wait 24 s for clicking availability? i couldn't get yet? what's strange I can easily click the first li >div> a item
I found the reason why, it is not clickable. View...When scrolling down the screen, it clicks easily. I will open new question thread

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.