0

I'm currently using a Macbook Air running OS X El Capitan. I'm using the Python IDLE and trying to select and click on the following webpage button:

<div class="search-form-actions">
  <button class="btn btn-submit js-search-form-submit" selector=".js-search-form-submit" helptip="When you are ready to view all the contacts that match your criteria, click View Results." data-placement="top" data-step-number="5" data-step-name="Get Results">View Results</button>
</div>

By using the following script:

from selenium import webdriver
browser = webdriver.Firefox()
type(browser)
browser.get('https://app.avention.com/')

#enter username
usernameElem = browser.find_element_by_name("username")
usernameElem.send_keys('myusername')
usernameElem.submit()

#enter password
usernameElem = browser.find_element_by_name("password")
usernameElem.send_keys('mypassword')
usernameElem.submit()

#selecting 'Saved Searches' page
htmlElem = browser.find_element_by_tag_name("html") #without this line, site blocks next command
browser.get('https://app.avention.com/search/saved/7a1fbf2d-329a-4fda-8c51-4be5bc07317c#')

#selecting 'View Results' button
resultsElem = browser.find_element_by_class_name("btn.btn-submit.js-search-form-submit").click()

I receive the following error:

NoSuchElementException: Message: Unable to locate element: {"method":"class name","selector":"btn.btn-submit.js-search-form-submit"}

I have tried to find_element_by_class_name

I have tried to find_element_by_name

I have tried to find_element_by_id

I have tried to find_element_by_link_text

But with no success. Any suggestions. Many thanks.

Gavin.

1 Answer 1

1

class_name receives one class name

browser.find_element_by_class_name("btn")
# or
browser.find_element_by_class_name("btn-submit")
# or
browser.find_element_by_class_name("js-search-form-submit")

If you want all the classes together use css_selector

browser.find_element_by_css_selector(".btn.btn-submit.js-search-form-submit")

You also can't assign the results to variable and click on it in the same time. It should be

resultsElem = browser.find_element_by_class_name("btn")
# or
browser.find_element_by_class_name("btn").click()
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Guy, that helped a lot, it turns out the button had a different class_name all together but your correction of separating the assignment and click function would have saved me further headache. cheers

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.