Home > Back-end >  Selenium Webdriver Python Click Doesn't Seem to be working
Selenium Webdriver Python Click Doesn't Seem to be working

Time:11-09

I'm trying to login to my Wegmans account to export my orders into a spreadsheet. I'm using Selenium and chromedriver in Docker. My issue is that clicking the next button on the login/sign in page isn't having any effect on the page.

Here's my code:

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

print("Waiting for Webdriver to be available")
time.sleep(5)
print("Done waiting")

driver = webdriver.Remote(
   command_executor='http://chrome:4444/wd/hub',
   desired_capabilities=DesiredCapabilities.CHROME)
wait = WebDriverWait(driver, 20)
driver.maximize_window()

print("Opening Wegmans")
driver.get("https://shop.wegmans.com/login")
wait.until(EC.title_contains('Sign in'))

email = driver.find_element_by_id("signInName")
password = driver.find_element_by_id("password")

email.send_keys("[email protected]")
password.send_keys("password")

driver.find_element_by_id("next").click()
driver.save_screenshot("/tmp/app/rightafterclick.png")
time.sleep(20)
driver.save_screenshot("/tmp/app/20secondsafterclick.png")

Both screenshots show the same thing - which is the email and password filled out but no change in the page. The 2nd screenshot should contain an error message because the email is not valid. The element id's are correct. How can I ensure that the "Sign In" button gets clicked?

CodePudding user response:

I had solved your problem by using below code

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


option = webdriver.ChromeOptions()
option.add_argument('--disable-blink-features=AutomationControlled')
option.add_argument("start-maximized")
option.add_experimental_option(
    "excludeSwitches", ["enable-automation"])
option.add_experimental_option('useAutomationExtension', False)

driver = webdriver.Chrome(options=option)

wait = WebDriverWait(driver, 20)
driver.maximize_window()

print("Opening Wegmans")
driver.get("https://shop.wegmans.com/login")
wait.until(EC.title_contains('Sign in'))

time.sleep(5)

email = driver.find_element_by_id("signInName")
password = driver.find_element_by_id("password")

email.send_keys("[email protected]")
password.send_keys("password")

driver.find_element_by_id("next").click()
driver.save_screenshot("rightafterclick.png")
time.sleep(20)
driver.save_screenshot("20secondsafterclick.png")
  • Related