简体   繁体   中英

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.

<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.

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.

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