How can I find html elements base on wfd-id using selenium?

Viewed 2232

I'm trying to automate a website that use wfd-id to identify html elements. Since most of the html elements in this website use wfd-id, it will make my program much faster if I can use findelement with wfd-id. I have tried using driver.FindelementsbyId, but it didn't work. I also tried to look print out attribute with "wfd-id", it also didn't print out anything.

Any help would be very much appreciated.

enter image description here

I actually can use FindElementsbyTag and then loop through the collection to look for the html text, but I noticed that each element has a unique wfd-id so it might be better if I can find element by wfd-id instead.

3 Answers

You can use css and form your selector such as tag[wfd-id='foo']

For example. If you have an element <div wfd-id="username">, you could select it using:

"div[wfd-id='username']"

Hard to say until you provide HTML and your existing code.

You can use an attribute CSS selector to match on the attribute wfd-id and apply via .FindElementsByCss to return the collection of WebElements. You then loop and access individual elements content using .Text property.

Dim elems As WebElements, elem As WebElement
Set elems = bot.FindElementsByCss("[wfd-id]")
For Each elem In elems
    Debug.Print elem.Text
Next

If you are sure that its id is unique then you can use xpath in findelement;

driver.findelement(By.xpath("//*[@wdf-id='905']"))
Related