简体   繁体   English

如何单击硒python中的按钮

[英]How to click a button in selenium python

I am using Python script to open a web page, then a tab and then i want to click on a button.我正在使用 Python 脚本打开一个网页,然后是一个选项卡,然后我想单击一个按钮。 I am stuck on the last part.我被困在最后一部分。 I am unable to click the find button.我无法单击查找按钮。 Here is the HTML code when i am using inspect in chrome.这是我在 chrome 中使用检查时的 HTML 代码。

代码片段

input value="Find" class="cuesButton" name="findButton" 
onclick="javascript:onFindSubmit()" type="button"

Here is the button i am trying to click:这是我试图点击的按钮:

按钮点击

I tried driver.find_element_by_name, element_by_id.我试过driver.find_element_by_name、element_by_id。 It says method css selector doesnt have this element by name but it still fails.它说方法 css 选择器没有这个元素的名称,但它仍然失败。

2 things can be happening, 1 the page isn't finished loading, to wait use WebDriverWait like so:可能发生 2 件事,1 页面未完成加载,等待使用 WebDriverWait,如下所示:

wait = WebDriverWait(driver, 10)等待 = WebDriverWait(驱动程序,10)

Or 2, the element is in an iframe , in this case you would need to switch to it like so:或者 2,元素在 iframe 中,在这种情况下,您需要像这样切换到它:

driver.switch_to.frame(driver.find_element_by_tag_name("iframe")) driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))

You can switch using xpath, name, cssselector, and tag name可以使用 xpath、name、cssselector 和 tag name 进行切换

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

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