简体   繁体   中英

Using selenium to click search button

I am trying to click the search button in this link here

I would like to click the search button and then download all URL's on the next page but currently it is finding monthly list

The link below takes you to a screenshot of my code where it outputs the monthly list button instead of searcj/

Python code selenium

Welcome to Stack Overflow!

You can use the .click() method to click an element object, and the .find_element_by_xpath() method to find the element. I've located that the element's full XPATH is /html/body/div/div/div[3]/div[3]/div/form/fieldset/div[5]/input[2] .

You can implement all the pieces together like so:

driver.find_element_by_xpath("/html/body/div/div/div[3]/div[3]/div/form/fieldset/div[5]/input[2]").click()

if you are starting I recommend you using some extension to help you find the xPath of the elements. I used Xpath Helper from Chrome, but you can use any other.

The Xpath of the Search button is:

/html[@class='js']/body/div[@id='idox']/div[@id='pa']/div[@class='container'][2]/div[@class='content']/div[@class='tabcontainer']/form[@id='weeklyListForm']/fieldset/div[@class='buttons']/input[@class='button primary']

After you have the XPath you can use it in the selenium driver to find the elements.

This can be enough, but I recommend you to learn in depth how this works to know exactly what it is doing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM