1

Trying selenium for a webpage which only have google authentication. When the Join button is clicked, a popup window comes up which only have a button named sign uo with google. As i am new to salenium, i am not able to access to the popup window button.

import time

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

from time import sleep

driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://shatkora.co/grocery")

oin_btn=driver.find_element_by_xpath('//*[@id="layout-header"]/div/button')
join_btn.click()

time.sleep(5)
button=driver.find_element_by_xpath('//*[@id="__next"]/div[1]/div/div[6]/div/div/div/div[1]/button')

2
  • I believe that form is in iframe so switch to that frame first.
    – Alexey R.
    Sep 2 at 10:45
  • That was not in an i-frame. its a separate module which becomes visible when the Join button clicked. And I cant access to that module. Sep 6 at 3:24
1

That's actually quite an interesting case. First of all this code will work:

import time

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

driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://shatkora.co/grocery")

join_btn = driver.find_element_by_xpath('//*[@id="layout-header"]/div/button')
join_btn.click()

wait = WebDriverWait(driver, 10)
signIn = wait.until(EC.element_to_be_clickable((By.XPATH, '//button[text()="Sign in with Google"]')))

time.sleep(5)
signIn.click()
# Commenting below line for the sake of demo
# driver.quit()

What's unusual here is that any sort of looking the element up would be successful however that won't be enough.

As far as I understand there is a quick animation of that area and despite the element is already in DOM and active (that is why expected conditions work here) it still cannot be clicked (either blocked by a script or the case in the changing coordinates of element - I do not know) unless animation is completed.

So after you have looked up an element you also have to wait for the animation to finish. The easiest way is to add explicit wait. Another - more complicated but less blocking - is to wait for certain CSS values for the area.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.