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.
Answers:
Like barak manos said the answer was:
'//*[@title="Havai 30"]'
With [0] at ending, case it was list.
browser.find_element_by_xpath('//*[@title="Havai 30"]').click()
This Will Work for me Like you said.
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();
This works for me:
driver.find_element_by_xpath('//*[@title="Havai 30"]').click()
** Make sure you include the starting and ending square brackets!
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.
Like barak manos said the answer was:
'//*[@title="Havai 30"]'
With [0] at ending, case it was list.
browser.find_element_by_xpath('//*[@title="Havai 30"]').click()
This Will Work for me Like you said.
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();
This works for me:
driver.find_element_by_xpath('//*[@title="Havai 30"]').click()
** Make sure you include the starting and ending square brackets!