Home > other >  Selecting an element that has a specific text and specific title Selenium
Selecting an element that has a specific text and specific title Selenium

Time:08-07

I have the following DOM

>     <a  title="Inno 3D GeForce RTX 3080 10GB GDDR6X X3 LHR Κάρτα Γραφικών PCI-E x16 4.0 με HDMI και 3
> DisplayPort" data-e2e-testid="sku-price-link"
> href="/s/35993359/Inno-3D-GeForce-RTX-3080-10GB-GDDR6X-X3-LHR-Κάρτα-Γραφικών-PCI-E-x16-4-0-με-HDMI-και-3-DisplayPort-N30803-106X-1810VA44H.html">
>         <span>από</span>
>         871,28 €
>     </a>

as you can see it has a class and a title. There are other elements in the page that have the same a class ("js-sku-link sku-link") but i want to be able to define based on the title which one i want. In this case i want the one that it has in title the text RTX 3080. I tried the following without any luck

driver.find_element_by_xpath('//div[@data-e2e-testid="sku-price-link" and text()="RTX 3080"]').text
driver.find_element_by_xpath("//a[@title='6950']")

Please help

CodePudding user response:

Try this XPath expression:

driver.find_element_by_xpath('//a[@data-e2e-testid="sku-price-link" and contains(@title,"RTX 3080")]').text

The result is the text content of the <a> element:

από
871,28 €

CodePudding user response:

Which browser you are using? You can inspect the specific element and get the Xpath of the value of the element you are inspecting in the browser.

  • Related