Using Python 3.
Situation:
I select some elements with a certain xpath query.
There are many matches for that xpath query.
I want to grab the exact match corresponding with the element that is visible at the moment.
Notes:
There are always N matches (being N greater than 1.)
There is always only one match that is visible.
Actually, this is about pop-ups being displayed or not with javascript at certain moments.
Question:
How can iterate on all those results and know which one is visible by the user?
UPDATE:
The website is: go to website
If you wait a few seconds, there is a popup being displayed.
My xpath query is:
//div[@class='wrapper-code-reveal']//input[@class='code']
But there are 23 matches in this case.
How may I get the exact match that is being displayed?
I tried clicking it, which would give an exception when not visible.
codigos_descuento = driver.find_elements_by_xpath("//div[@class='wrapper-code-reveal']//input[@class='code']")
for codigo in codigos_descuento:
try:
codigo.click()
codigo_descuento_texto = codigo.get_attribute('value')
except:
print(traceback.format_exc())
continue