Reputation:
I have a problem, I'm trying to make a script that automatically logs into this site https://www.nike.com.br/cosmic-unity-153-169-211-324680 The problem is that after a few seconds this page loads and you must select the size of the shoe and click on the button that is written "Faça login para comprar" ok, after my bot clicks there it opens a pop up where i must inform my email and password and click on the login button, the problem is that i'm trying and i can't click on the input to fill in the email and password and neither I can click on the login button, I believe that maybe it is due to the fact that it is inside a div
My code:
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
option = Options()
prefs = {'profile.default_content_setting_values': {'images': 2}}
option.add_experimental_option('prefs', prefs)
driver = webdriver.Chrome(options = option)
driver.get("https//www.nike.com.br/cosmic-unity-153-169-211-324680")
wait = WebDriverWait(driver, 10)
wait.untilEC.element_to_be_clickable((By.CSS_SELECTOR, '.cc-allow'))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, '//label[@for="tamanho__id40"]'))).click()
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'button#anchor-acessar-unite-oauth2'))).click()
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'input#9f656f67-dbed-4cda-be83-0d0d0addc6f4'))).send_keys("[email protected]")
wait.untillEC.element_to_be_clickable((By.CSS_SELECTOR, 'input#7016e824-f431-43d0-b5c9-d0331c330014'))).send_keys("mypass")
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'button#a7f38f9a-afd7-42ce-a978-314a7d484343'))).click()
Order this code and realize that it only works until you open the login popup, after that it generates this error:
selenium.common.exceptions.TimeoutException: Message:**
Upvotes: 1
Views: 429
Reputation: 29362
That pop up is inside an iframe, you need to switch your driver focus to that particular iframe.
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID,"nike-unite-oauth2-iframe")))
make sure once you are done with that pop up switch to default_content to proceed further.
driver.switch_to.default_content()
Update 1 :
driver = webdriver.Chrome("C:\\Users\\etc\\Desktop\\Selenium+Python\\chromedriver.exe")
driver.maximize_window()
wait = WebDriverWait(driver, 30)
driver.get("https://www.nike.com.br/cosmic-unity-153-169-211-324680")
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '.cc-allow'))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//label[@for='tamanho__id40']"))).click()
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'button#anchor-acessar-unite-oauth2'))).click()
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID,"nike-unite-oauth2-iframe")))
wait.until(EC.element_to_be_clickable((By.NAME, 'emailAddress'))).send_keys("[email protected]")
wait.until(EC.element_to_be_clickable((By.NAME, 'password'))).send_keys("mypass")
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[value='ENTRAR']"))).click()
Upvotes: 1