3

I'm new to python selenium and I'm trying to click on a button which has the following HTML structure:

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

I have tried this to click on Submit Button.

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

But i always end up with error

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

1 Answer 1

4

find_element_by_css_selector('btn btn-primary') will look fir an element with tag btn-primary that has ancestor element with tag btn.

You need to tell the driver those are classes with .

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

Or explicitly

driver.find_element_by_css_selector('[class="btn btn-primary"]').click()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.