Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find and click element by title Python Selenium

Tags:

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 image 887
cask Avatar asked Aug 18 '14 13:08

cask


People also ask

How do you click on an element title?

We can find and click elements by title in Selenium webdriver. An element can be identified with a title attribute with xpath or css selector. With the xpath, the expression should be //tagname[@title='value']. In css, the expression should be tagname[title='value'].

How do you click XPath in Python?

We can click a button with Selenium webdriver in Python using the click method. First, we have to identify the button to be clicked with the help of any locators like id, name, class, xpath, tagname or css. Then we have to apply the click method on it. A button in html code is represented by button tagname.

What is find element by name in Selenium?

Go to the First name tab and right click >> Inspect. On inspecting the web element, it will show an input tag and attributes like class and id. Use the id and these attributes to construct XPath which, in turn, will locate the first name field.

How do I find an element that contains specific text in Selenium Webdriver?

We can find an element that contains specific text with Selenium webdriver in Python using the xpath. This locator has functions that help to verify a specific text contained within an element. The function text() in xpath is used to locate a webelement depending on the text visible on the page.


2 Answers

Like barak manos said the answer was:

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

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

like image 81
cask Avatar answered Sep 24 '22 18:09

cask


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

This Will Work for me Like you said.

like image 43
Arun V Jose Avatar answered Sep 22 '22 18:09

Arun V Jose