Reputation: 453
For the example, I'm navigating to https://google.com, then search for "Facebook"
.
the 2nd result is https://Facebook.com
the href
is:
href="/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&sqi=2&ved=0ahUKEwim2e368Y_SAhVHDcAKHXKfD0wQFgglMAA&url=https%3A%2F%2Fwww.facebook.com%2F&usg=AFQjCNGug_CqO9cxLI8dHdn-CceO8_ie5w&sig2=8e9cdct3GrJ8ZqdUiPsXCQ&bvm=bv.146786187,d.bGg"
I also get:
data-href="https://www.facebook.com/"
how can I find the element with this data?
Upvotes: 0
Views: 328
Reputation: 386
Don't evaluate data-href it is added dynamicly to the element only after a onmousedown event. You probably used the "inspect element" feature which triggers the event. Use ctrl-shift C instead to inspect elements.
You can simply click on : "//a[@href='https://www.facebook.com/']"
Upvotes: 0
Reputation: 52685
You can find required link By.cssSelector("a[data-href='https://www.facebook.com/']")
or using XPath
- By.xpath("//a[@data-href='https://www.facebook.com/']")
Upvotes: 1