[英]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.