简体   繁体   English

尝试自动单击 Selenium Python 模块中的搜索按钮,但它不起作用

[英]Trying to automate to click on Search button in Selenium Python module, but it is not working

I need help to automate to click the search button in this webpage.我需要帮助来自动单击此网页中的搜索按钮。 The code works so far, until I reach the search button.该代码到目前为止有效,直到我到达搜索按钮。 Below are the elements for this button.以下是此按钮的元素。 The value named Search is unique for this button.名为 Search 的值对于此按钮是唯一的。

<input type="button" value="Search" onclick="submitfilter();">

Below is the code:下面是代码:

from selenium  import webdriver
from selenium.webdriver.support.ui import WebDriverWait, Select
from selenium.common.exceptions import TimeoutException, NoSuchElementException
from selenium.webdriver.common.by import By

driver = webdriver.Chrome(executable_path='C:/chromedriver.exe')
driver.implicitly_wait(10)
url = "http://fake.com"
driver.get(url)
driver.maximize_window()
    
ABC = driver.find_element(By.XPATH("//input[@value="Search"]"))
ABC.click()

There is a syntactical error on that line, you're using double quotes for the Xpath and so for the value inside it, which makes the code treat search as a variable.该行存在语法错误,您对 Xpath 使用双引号,对其中的值使用双引号,这使得代码将搜索视为变量。

Change the line to:将行更改为:

ABC = driver.find_element(By.XPATH('//input[@value="Search"]'))
ABC = driver.find_element(By.XPATH,"//input[@value='Search']")

The proper way to write this would be like so.写这个的正确方法是这样的。 Not calling the By.xpath with the string of the xpat.不使用 xpat 的字符串调用 By.xpath。

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

相关问题 Python Selenium 尝试单击按钮不起作用 - Python Selenium trying to click button not working 无法使用 Python 自动单击 Selenium 中的按钮 - Unable to automate the click of a button in Selenium with Python 如何自动化 Selenium 以单击图像按钮 - 通过 onclick 查找元素? - Python - How to automate Selenium to click image button - find element by onclick? - Python 尝试单击 paypal 上的继续按钮,python 中的 Selenium - Trying to click continue button on paypal with Selenium in python 使用带有 -selenium -python 的类单击按钮搜索 - Click on a button search using classes with -selenium -python 如何使用 Python Selenium 点击搜索按钮 - How to click on Search button using Python Selenium 无法使用Selenium / Python单击搜索结果的按钮 - Unable to click on button of a search result with Selenium / Python Selenium Python - 下载 button.click() 不再工作 - Selenium Python - download button .click() no longer working Python selenium 点击按钮 class 不工作 - Python selenium click button by class not working Python Selenium - 自动填写表单 - 单击不是提交按钮的按钮并从列表中填写表单 - Python Selenium - Automate filling forms - Click on a button that is not a submit button and filling in a form from a list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM