Python 如何使用selenium单击只有类型和类的按钮
我尝试使用selenium在Expedia上单击“提交”按钮。但这些方法都不起作用Python 如何使用selenium单击只有类型和类的按钮,python,selenium,selenium-chromedriver,Python,Selenium,Selenium Chromedriver,我尝试使用selenium在Expedia上单击“提交”按钮。但这些方法都不起作用 我厌倦了XPath,但它不起作用。。。实际上,我不确定应该将哪个类输入XPATHs函数。如果您试图单击按钮,可以使用以下方法 driver = webdriver.Chrome(r"your_path_to_chromedriver\chromedriver.exe") #path to connect with webdriver and chrome driver.get("https://www.your_
我厌倦了XPath,但它不起作用。。。实际上,我不确定应该将哪个类输入XPATHs函数。如果您试图单击按钮,可以使用以下方法
driver = webdriver.Chrome(r"your_path_to_chromedriver\chromedriver.exe") #path to connect with webdriver and chrome
driver.get("https://www.your_website.com")
driver.find_element_by_id("enter_id").click() #add the id of button to click
driver.find_element_by_class_name("enter_class").click() #add the class of button to click
driver.find_element_by_xpath("enter_expath").click() #add the xpath to click on button
您可以使用id、class或Xpath的任何方法来获取元素并单击它。下面的任一代码都可以工作
//button[@type='submit'][@class='btn-primary.btn-action.gcw-submit']
//button[type='submit'][class='btn-primary.btn-action.gcw-submit']
iframe中不存在第一个验证元素。如果可以找到该元素,请尝试单击父元素。它大部分时间都有效。