Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用selenium单击只有类型和类的按钮_Python_Selenium_Selenium Chromedriver - Fatal编程技术网

Python 如何使用selenium单击只有类型和类的按钮

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_

我尝试使用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_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中不存在第一个验证元素。如果可以找到该元素,请尝试单击父元素。它大部分时间都有效。