How do I use the Selenium Click function

Question:

I am trying to click a login button after filling out all the information for the website. So far I have been able to fill in spaces using driver.find_element("id","username").send_keys("username") when I use driver.find_element_id("username").send_keys("username") it wont work.

The login button elements are class=radius and type=sumbit also i class="fa fa-2x fa-sign-in"
(I would just link the site but I dont know if that would be against TOS)

So far I have used the following commands
element = driver.find_element_by_link_text("Login")
element.click()
driver.find_element_by_xpath(//*[@id="login"]/button.click() but xpath gives an "unresolved reference"

I am using IDE PyCharm Build #PC-222.4167.33 on Windows

Asked By: Roman Hall

||

Answers:

Looks like the same problem I solve here Selenium, selecting from dropdown

You should localize the element with XPath or CSS selector, i recommend you try with CSS selector, if don’t work try with xpath .

Try this code:

driver.find_element(By.ID, "username").send_keys("<enter the username>")
driver.find_element(By.ID, "password").send_keys("<enter the password>")
time.sleep(1)
driver.find_element(By.CSS_SELECTOR, ".radius").click()
time.sleep(2)
driver.find_element(By.CSS_SELECTOR, ".button.secondary.radius").click()
time.sleep(2)

I have added ‘time.sleep()‘ just to show you it is working correctly, avoid using it in your real-time projects.

Answered By: AbiSaran
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.