0

Hi guys I have the issue as a question that was answered called: How do I select only visible elements using XPath?

The response was: //div[not(contains(@style,'display:none'))]//button[.='OK'].

My question is how do I adapt the above for aria-hidden='true', I'm trying to find elements that are only aria-hidden='false'?

I do apologize if my approach is messy, I'm kinda new to asking questions on here

Thanks

Mate Mrše
  • 7,328
  • 9
  • 29
  • 68
  • There is no silver bullet to do that because element may be not visible due to lot's of reasons – Mike G. Jan 20 '21 at 08:48

3 Answers3

0

You can try adding another search criteria, depending on if the aria-hidden='false' applies to the div

//div[not(contains(@style,'display:none')) and @aria-hidden='true')]//button[.='OK']

or the button

//div[not(contains(@style,'display:none'))]//button[.='OK' and @aria-hidden='true']

There are some more examples here.

Mate Mrše
  • 7,328
  • 9
  • 29
  • 68
0

If I understand well, you could adapt with your example this way:

driver.find_element_by_xpath("//div[@aria-hidden='false']//button[.="OK"]")

Don't hesitate to share an URL or HTML code if my answer is not correct.

0

Finally with more than an hour of searching, trial and error, I found what I was looking for ^-^.. the pain

//a[contains(@aria-hidden, 'false') and contains(.,'text')]