spak
spak

Reputation: 253

How to click on the button with text as Search as per the html through Selenium and Python?

I am trying to use Selenium to click a "Search" Button but I cant seem to locate it.

<div class="search">
            <input type="submit" title="Search" value="Search" class="spinner">
</div>              

My code looks like this:

search_button = driver.find_element_by_class_name("spinner")
search_button.send_keys(Keys.RETURN)

Any help would be much much appreciated. Thank you

Upvotes: 2

Views: 402

Answers (2)

undetected Selenium
undetected Selenium

Reputation: 193108

As per the HTML you have shared to invoke click() on the button with text as Search you can use either of the following solutions:

  • Using click():

    driver.find_element_by_xpath("//input[@class='spinner' and @title='Search']").click()
    
  • Using submit():

    driver.find_element_by_xpath("//input[@class='spinner' and @title='Search']").submit()
    

Upvotes: 2

Amit Jain
Amit Jain

Reputation: 4597

You can try like this

driver.find_element_by_css_selector(".spinner")
driver.find_element_by_xpath("//div[@class='search']/input")
driver.find_element_by_xpath("//input[@type='submit' and @title='Search']")
driver.find_element_by_xpath("//input[@type='submit' and @value='Search']")
driver.find_element_by_xpath("//input[@title='Search']")
driver.find_element_by_xpath("//input[@value='Search']")

elementByXpath = driver.find_element_by_xpath("//div[@class='search']")
elementByXpath.find_element_by_tag_name("input").send_keys(Keys.RETURN)

Upvotes: 0

Related Questions