Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Selenium finding link by text when text-transform present

I have this HTML

<div class="tabsAction">
  <a class="butAction" href="" title="" data-original-title="">Validar</a>
  <a class="butAction" href="" title="" data-original-title="">Copiar</a>
  <a class="butAction" href="" title="" data-original-title="">Convertir en plantilla</a>
  <a class="butActionDelete" href="" title="" data-original-title="">Eliminar</a>
</div>

I’m trying to select the Validar link.

driver.find_element(By.LINK_TEXT, "Validar")

but selenium can’t find it.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

However if I do this:

for link in links:
    print(link.text)

I get this:

VALIDAR
COPIAR
CONVERTIR EN PLANTILLA
ELIMINAR

I’ve checked and the class .butAction has a text-transform: uppercase; css.

I swear this 100% used to work just yesterday, why is it not working now? What am I missing?

>Solution :

Instead of By.LINK_TEXT it’s better to use By.XPATH.
In this case you only need to know what text appears in the web element on the page, not how it presented to user.
This should work:

driver.find_element(By.XPATH, "//a[@class='butAction'][text()='Validar']")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading