Home > database >  How do I use the Selenium Click function
How do I use the Selenium Click function

Time:10-17

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

CodePudding user response:

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.

CodePudding user response:

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 .

  • Related