Find and click element by title Python Selenium

Question:

I am looking site. In inspect element see this:

<span id="item60" title="Havai 30" class="item button link">Get</span>
<span id="item90" title="Classic 50" class="item button link">Get</span>

Need to get and click element by title. Something like this:

browser.find_element_by_xpath('//*[@id="item60"]').click()

But via title.

Asked By: cask

||

Answers:

Like barak manos said the answer was:

'//*[@title="Havai 30"]'

With [0] at ending, case it was list.

Answered By: cask
browser.find_element_by_xpath('//*[@title="Havai 30"]').click()

This Will Work for me Like you said.

Answered By: Arun V Jose

For me works with Page Object Pattern:

@FindBy(xpath = "//*[@title='Havai 30']")
WebElement imHavai;

For java if someone was looking for the answer here like me:

String title="SOME TITLE";
driver.findElement(By.cssSelector("[title^='"+title+"']")).click();
Answered By: xMilos

This works for me:

driver.find_element_by_xpath('//*[@title="Havai 30"]').click()

** Make sure you include the starting and ending square brackets!

Answered By: Ahmed Al-Jaishi
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.