简体   繁体   English

使用 selenium 点击搜索按钮

[英]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我想单击搜索按钮,然后在下一页下载所有 URL,但目前正在查找月度列表

The link below takes you to a screenshot of my code where it outputs the monthly list button instead of searcj/下面的链接将您带到我的代码的屏幕截图,它输出每月列表按钮而不是 searcj/

Python code selenium Python 代码 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.您可以使用 .click .click()方法单击元素 object,并使用.find_element_by_xpath()方法查找元素。 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] .我发现元素的完整 XPATH 是/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.如果您开始我建议您使用一些扩展来帮助您找到元素的 xPath。 I used Xpath Helper from Chrome, but you can use any other.我使用了 Chrome 中的 Xpath Helper,但您可以使用任何其他的。

The Xpath of the Search button is:搜索按钮的 Xpath 为:

/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.拥有 XPath 后,您可以在 selenium 驱动程序中使用它来查找元素。

This can be enough, but I recommend you to learn in depth how this works to know exactly what it is doing.这已经足够了,但我建议您深入了解它是如何工作的,以确切了解它在做什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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