0

I cannot login to this site.

This is the url.

https://swayam.gov.in/azurelogin?continue=/

What I tried:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://swayam.gov.in/azurelogin?continue=/")
login_google_btn = driver.find_element_by_xpath('//*[@id="GoogleExchange"]')
login_google_btn.click()

I need to login with google and hence required to click that button.

Output:

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate 
element: {"method":"xpath","selector":"//*[@id="next"]"}
(Session info: chrome=80.0.3987.106)

Then, I checked to send keys to the username and password fields, but encountered similar error.

What's going wrong?

3
  • After clicking Google button, it redirects to another page which doesnt have the Next button. That is probably why this error shows up. Commented Feb 16, 2020 at 11:12
  • Try ...by_xpath("/html/body/div[2]/div[2]/div[1]/div[2]/div[2]/button") Commented Feb 16, 2020 at 11:13
  • 1
    it needs time to load page - you could use time.sleep(1) after driver.get() Commented Feb 16, 2020 at 12:32

1 Answer 1

1

It seems it uses JavaScript to load data and you have to wait a little for elements on page.

You can use time.sleep(1) or driver.implicitly_wait(1) to wait 1 second.

from selenium import webdriver
#import time

driver = webdriver.Chrome()
driver.implicitly_wait(1)

driver.get("https://swayam.gov.in/azurelogin?continue=/")
#time.sleep(1)

#login_google_btn = driver.find_element_by_id('GoogleExchange')
login_google_btn = driver.find_element_by_xpath('//*[@id="GoogleExchange"]')
login_google_btn.click()

See doc Waits for other methods.

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

driver = webdriver.Chrome()
driver.get("https://swayam.gov.in/azurelogin?continue=/")

wait = WebDriverWait(driver, 10)
#login_google_btn = wait.until(EC.element_to_be_clickable((By.ID, 'GoogleExchange')))
login_google_btn = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="GoogleExchange"]')))
login_google_btn.click()
Sign up to request clarification or add additional context in comments.

3 Comments

Works like a charm! time.sleep(1) simply holds for 1 second whereas I'm confused with driver.implicitly_wait(1). Please clarify what's going around and the difference between both.
you have link to Waits and there you will get all information.
implicitly_wait(1) will wait 1 second after get() load page before it gets DOM with HTML and run next code in your script. time.sleep() is simple method to wait but selenium has implicitly_wait for this. Using wait.until() you can set longer time and it will check every 0.5s if element is ready

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.