0

I am trying to login to woolworths website using selenium. But after entering email and password, when I click on login button, nothing happens. I have tried everything I can find on internet but its no use. It`s a simple login but now it is driving me crazy. I am sharing the code below:

driver = webdriver.Chrome()
driver.get("https://www.woolworths.com.au/shop/securelogin")
loginform = driver.find_element_by_id('loginForm')
user = loginform.find_element_by_id("loginForm-Email")
user.send_keys("myemail")
pas = loginform.find_element_by_id("loginForm-Password")
pas.send_keys("mypass")
pas.submit()

Image:

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

3 Answers3

1

To login into the website you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    driver.get('https://www.woolworths.com.au/shop/securelogin')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#loginForm-Email"))).send_keys("myemail")
    driver.find_element_by_css_selector("input#loginForm-Password").send_keys("mypass")
    driver.find_element_by_css_selector("button[type='submit']").click()
    
  • Using XPATH:

    driver.get('https://www.woolworths.com.au/shop/securelogin')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='loginForm-Email']"))).send_keys("myemail")
    driver.find_element_by_xpath("//input[@id='loginForm-Password']").send_keys("mypass")
    driver.find_element_by_xpath("//button[@type='submit']").click()
    
  • Note : You have to add the following imports :

      from selenium.webdriver.support.ui import WebDriverWait
      from selenium.webdriver.common.by import By
      from selenium.webdriver.support import expected_conditions as EC
    

Browser Snapshot:

woolworths

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • that's not the problem.. as you can see in his screenshot, he clicked on the login button and the loading spinner appeared after instead of "login" text. – Razvan Sep 01 '20 at 15:11
  • After login button is pressed, the spinner appears in place of login button text and nothing happens. – Adeel Ahmed Sep 01 '20 at 15:26
  • @Razvan Before the login request is sent of coarse there will be _username_ and _password_ validation through `onclick` event. So unless you provide us a demo set of working credentials we would be unable to repro the loading issue. We can only help you to invoke click on the desired button. – undetected Selenium Sep 02 '20 at 08:51
0

I faced a similar issue and all I can say that this can have 2 roots: weak internet connection or the server is a sloth. You can try to add a wait until loading icon inside of login button disappear (you will need to create a locator for it), or, perform the click action based on javascript:

driver.execute_script("document.getElementsByName('locator_name')[0].click();")
Razvan
  • 347
  • 1
  • 11
  • I can login to the website manually. It takes like 2 sec when login manually after clicking the login button. But when I am trying to login using selenium, after pressing login button, the spinner replaces the text in the button and nothing happens. The internet connection is fine also. – Adeel Ahmed Sep 01 '20 at 15:29
  • Mmm, but if you run it on another browser, is the same situation? – Razvan Sep 01 '20 at 20:07
0

For clicking on Login button, please use this xpath :

login= driver.find_element_by_xpath("//*[@id='loginForm']/fieldset/div/shared-button/button")
and then try:
login.submit()
Apps Maven
  • 1,314
  • 1
  • 4
  • 17