How can I find the log in button element? My script as below but not working after input username & password. Or shall I use find element by css selector or other? and how?
driver.find_element_by_name("username").send_keys(username) driver.find_element_by_name("password").send_keys(password) driver.find_element_by_class_name("cux-button ng-scope").click()
Advertisement
Answer
I assume that you are using Selenium and the Selenium Python bindings. (Tipp: Mention the library, you are using, in your question. :) )
The find_element_by_class_name()
method only allows searching for a single class name, as already discussed in this question. As mentioned in the answers to that question, you can use the find_element_by_xpath()
or find_element_by_css_selector()
methods for more complex queries.
In your scenario, CSS selectors are sufficiently powerfull, so let’s use them:
driver.find_element_by_css_selector(".cux-button.ng-scope").click()
For understanding CSS selectors, you might want to take a look into this tutorial by Sauce Labs, as recommended by the unofficial Python Selenium docs.