Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.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

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使用类单击按钮_Python_Selenium_Selenium Webdriver_Css Selectors_Selenium Chromedriver - Fatal编程技术网

Python使用类单击按钮

Python使用类单击按钮,python,selenium,selenium-webdriver,css-selectors,selenium-chromedriver,Python,Selenium,Selenium Webdriver,Css Selectors,Selenium Chromedriver,我是python selenium的新手,尝试单击一个具有以下HTML结构的按钮: <div class="wpsafe-top text-center"> <h1><strong><span style="color: #ce2525;">Click on Submit to Get Link</span></strong></h1><br> <form action="https:

我是python selenium的新手,尝试单击一个具有以下HTML结构的按钮:

<div class="wpsafe-top text-center"> 
  <h1><strong><span style="color: #ce2525;">Click on Submit to Get Link</span></strong></h1><br>
  <form action="https://url.com/post" method="post">
    <input type="hidden" name="getlink" value="NVudM3E">
    <input type="hidden" name="newwpsafelink" value="eyJsaW5rIjoiTlZ1ZE0zRSIsImFkczEiOiIiLCJhZHMyIjoiIiwibG9nbyI6IiIsImltYWdlMSI6Imh0dHA6XC9cL3RlY2hjb2RlY3MuY29tXC93cC1jb250ZW50XC91cGxvYWRzXC8yMDE5XC8xMlwvZ2VuLnBuZyIsImltYWdlMiI6Imh0dHA6XC9cL3RlY2hjb2RlY3MuY29tXC93cC1jb250ZW50XC91cGxvYWRzXC8yMDE5XC8xMlwvcGx6LnBuZyIsImltYWdlMyI6Imh0dHA6XC9cL3RlY2hjb2RlY3MuY29tXC93cC1jb250ZW50XC91cGxvYWRzXC8yMDE5XC8xMlwvY2xrLnBuZyIsImxpbmtyIjoiaHR0cHM6XC9cL3RlY2hjb2RlY3MuY29tP3NhZmVsaW5rX3JlZGlyZWN0PTUlNUIlOUQzcSIsImRlbGF5dGV4dCI6IjxiPjxoMiBzdHlsZT0nY29sb3I6cmVkJz5Mb2FkaW5nIExpbmsgLi4uIFdhaXQgPHNwYW4gaWQ9XCJ3cHNhZmUtdGltZVwiPjEyPFwvc3Bhbj4gU2Vjb25kczxcL2gyPjxcL2I+IiwiZGVsYXkiOiIxMiIsImFkYiI6IjIiLCJhZGIxIjoiIiwiYWRiMiI6IiJ9">
    <input class="btn btn-primary" type="submit" value="Submit">
  </form> 
</div>

find\u element\u by_css\u selector('btn btn primary')
将查找带有标记
btn primary
的元素,该元素的祖先元素带有标记
btn

您需要告诉
驱动程序
那些是

driver.find_element_by_css_selector('.btn.btn-primary').click()
或者明确地

driver.find_element_by_css_selector('[class="btn btn-primary"]').click()
driver.find_element_by_css_selector('[class="btn btn-primary"]').click()