Python Selenium 单击带有类的按钮



我是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>

我已经尝试过单击"提交"按钮。

driver.find_element_by_css_selector('btn btn-primary').click()

但我总是以错误告终

Message: no such element: Unable to locate element: {"method":"css selector","selector":".btn btn-primary"}

find_element_by_css_selector('btn btn-primary')看起来会是一个带有标签btn-primary的元素,该元素具有带有标签btn的祖先元素。

你需要告诉driver这些是带有.的类

driver.find_element_by_css_selector('.btn.btn-primary').click()

或明确

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

相关内容

  • 没有找到相关文章

最新更新