【问题标题】:Loaded website with Selenium chromedriver successfully but can't interact with it after使用 Selenium chromedriver 成功加载网站,但之后无法与之交互
【发布时间】:2019-04-11 07:24:27
【问题描述】:

我正在尝试使用 Selenium 和 ChromeDriver 与 Lowes 网站 (https://www.lowes.com/) 进行交互。加载主页后,我想更改位置,但无法与网站交互。手动和通过 Selenium 单击更改位置按钮会导致页面永远加载并最终引发 TimeOutException。关于为什么会出现这种情况以及可以采取哪些措施来解决问题的任何想法?

当我使用 Google Chrome、Mozilla Firefox 和 Internet Explorer 手动加载网站时,我已经加载了该网站并与之交互正常,所以我认为这不是网站本身的问题。

我还使用 Selenium 和 ChromeDriver 加载并与 40 多个其他网站进行交互,完全没有问题,所以我不认为这是 Selenium/ChromeDriver/Chrome 的问题以及任何版本不兼容问题。我的 Chrome 版本是 71.0.3578.98,我的驱动程序版本是 71.0.3578.137。我在 Python 3.6 上使用 Spyder 在 Windows NT 6.1.761 SP1 x86_64 上运行我的脚本(如下所示)。

我运行的代码如下:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time

def click_button(x_path)
    button = WebDriverWait(driver, 15).until(EC.presence_of_element_located((By.XPATH, x_path)))
    button = driver.find_element_by_xpath(x_path)
    button.click()
    time.sleep(2)
    pass

#the issue persists with and without the commented lines
url = 'https://www.lowes.com/'
try:
    #options = webdriver.ChromeOptions()
    #options.add_argument("start-maximized")
    #options.add_argument("disable-infobars")
    #options.add_argument("--disable-extensions")
    driver = webdriver.Chrome('C://Temp//chromedriver.exe') #,options=options)
    #driver.implicitly_wait(30)
    driver.get(url)
except Exception as e:
    print(e)

#The following code hasn't worked, nor has manually interacting with the website at this point

sign_up_save_close = '//*[@id="emailSignUpDialog"]/div[2]/div/div/div/button
button_click(sign_up_save_close)

find_store_x_path = '//*[@id="currentStoreWrapper"]/div/div[2]/div[2]/a'
button_click(find_store_x_path)

我怀疑这可能是网站如何与 ChromeDriver 进行独特交互的问题。

我查看了该网站是否知道它正在与 ChromeDriver 进行交互,但没有迹象表明该网站实际检测到 ChromeDriver,即使使用如上所示的自定义选项,同样的问题仍然存在。

我尝试在 Firefox 中使用 geckodriver 运行它,但我无法让我的 geckodriver 工作。不过,我想保留这个关于 Chrome 的问题。

有什么想法吗?

编辑:我将添加代码来处理注册和保存,但弹出窗口不是问题。就像我说的,我尝试过手动和代码与网站进行交互。单击“查找商店”最终会永久加载网站。我也对在某些位置访问本网站上的产品页面的其他解决方案持开放态度。

【问题讨论】:

  • 您是否通过 Selenium 处理弹出注册并保存
  • 首先你需要关闭弹出窗口..
  • @DebanjanB 问题不在于弹出窗口。我已经用代码编辑了我的帖子以关闭弹出窗口,但在尝试点击“查找商店”时,该网站仍然会永远加载。

标签: python-3.x selenium google-chrome selenium-webdriver selenium-chromedriver


【解决方案1】:
  • 您已将点击函数定义为click_button(),但您是 称它为button_click()
  • 您应该始终使用显式等待而不是睡眠。
  • 您必须等待关闭按钮可点击,点击关闭按钮后,您必须等待模式隐藏和主页可点击。
  • 我用 java 查过了。点击页面作品。但是使用 chromedriver 点击Find a store 按钮会显示Access Denied。所以显然这个网站有硒检测和阻止。

【讨论】:

    猜你喜欢
    • 2021-04-27
    • 1970-01-01
    • 2022-10-14
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 2019-12-28
    • 1970-01-01
    • 2022-07-06
    相关资源
    最近更新 更多