【问题标题】:Selenium Webdriver Python Click Doesn't Seem to be workingSelenium Webdriver Python Click 似乎不起作用
【发布时间】:2021-11-08 22:05:52
【问题描述】:

我正在尝试登录我的 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 是正确的。如何确保“登录”按钮被点击?

【问题讨论】:

  • 看起来它正在检测硒并且点击被冻结。
  • 没有 docker,当你运行它时,你会遇到同样的问题吗?
  • 没有 docker 也会发生同样的事情
  • 刚刚执行了您的代码,并观察到它单击了下一步按钮,但没有执行任何操作。更改 email.send_keys("abc") 并运行。你会看到,验证错误
  • 我能够检查该页面,当单击按钮时,我看到 POST 上有一个 403。当我不使用 selenium 时,不会发生这种情况。

标签: python selenium selenium-webdriver


【解决方案1】:

我已经用下面的代码解决了你的问题

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")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 2016-09-14
    • 2018-09-30
    • 1970-01-01
    相关资源
    最近更新 更多