21
votes

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.

4
Well... Have you tried the obvious xpath '//*[@title="Havai 30"]'??? - barak manos
That worked! With [0] at ending. Was getting list. - cask

4 Answers

28
votes

Like barak manos said the answer was:

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

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

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

This Will Work for me Like you said.

4
votes

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

String title="SOME TITLE";
driver.findElement(By.cssSelector("[title^='"+title+"']")).click();
-1
votes

For me works with Page Object Pattern:

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