Selenium Webdriver Python Click似乎不起作用



我正试图登录我的Wegmans帐户,将我的订单导出到电子表格中。我在Docker中使用Selenium和chromedriver。我的问题是,点击登录/登录页面上的下一个按钮对页面没有任何影响。

这是我的代码:

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("myemail@yahoo.com")
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")

两张截图显示的是相同的内容,即填写的电子邮件和密码,但页面没有更改。第二张屏幕截图应该包含一条错误消息,因为该电子邮件无效。元素id正确。我如何才能确保;登录";按钮被点击了?

我使用以下代码解决了您的问题

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("myemail@yahoo.com")
password.send_keys("password")
driver.find_element_by_id("next").click()
driver.save_screenshot("rightafterclick.png")
time.sleep(20)
driver.save_screenshot("20secondsafterclick.png")

最新更新