I was trying to use python selenium to log in to a website. But the login is in a bootstrap modal dialog box, I cannot log in successfully using my code. Could someone please let me know what is wrong with my code?
I have tried the following code:
import requests
import time
import os, sys
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver import ActionChains
gecko = os.path.normpath(os.path.join(os.path.dirname(__file__), 'geckodriver'))
binary = FirefoxBinary(r'C:/Program Files/Mozilla Firefox/firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary, executable_path=gecko +'.exe')
driver.maximize_window()
wait = WebDriverWait(driver, 10)
time.sleep(1)
pageurl = "https://www.producemarketguide.com"
driver.get(pageurl)
popup = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="close-dialog"]')))
popup.click()
time.sleep(2)
login = wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/header/div/div[2]/div[2]')))
login.click()
user = wait.until(EC.presence_of_element_located((By.XPATH, '/html/body/app-main/app-widget/screen-layout/main/current-screen/div/screen-login/p[3]')))
user.send_keys('xxx@gmail.com')
password = wait.until(EC.presence_of_element_located((By.XPATH, '/html/body/app-main/app-widget/screen-layout/main/current-screen/div/screen-login/p[4]/input')))
password.send_keys('XXXX')
submit = wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/app-main/app-widget/screen-layout/main/current-screen/div/screen-login/p[6]/button')))
submit.click()
The error message I got is
Traceback (most recent call last):
File "pmg.py", line 34, in <module>
user = wait.until(EC.presence_of_element_located((By.XPATH, '/html/body/app-main/app-widget/screen-layout/main/current-screen/div/screen-login/p[3]')))
File "C:\Program Files\Python38\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: