2

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

1
  • have you tried locating with other locators like css selector,xpath? Also, are you getting any exception? Commented Aug 22, 2018 at 18:46

2 Answers 2

2

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()
    
Sign up to request clarification or add additional context in comments.

4 Comments

OP's requirement is python, not java.
@theGuy above code is valid for python. You can cross check in pycharm.
@Amit it is valid now, my comment was for his original answer before the edit.
@spak Upvote the answer if this/any answer is/was helpful to you for the benefit of the future readers.
0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.