0

我是论坛的新手,如果我错过了这个论坛的任何礼仪,请原谅我。我是在 Selenium Webdriver 中使用 Python 编写自动化脚本的学习者。

在这里,我正在尝试编写一个简单的代码来访问 lowes.com/stores --> 在搜索框中输入邮政编码 --> 单击查找按钮并查看结果。当我使用下面的代码执行此操作时,我成功地在搜索框中输入了邮政编码,但之后什么都没有发生。当我尝试在自动浏览器上手动单击查找按钮时,它显示我们很抱歉,请稍后再试。我已经粘贴了下面的代码。我还尝试使用完整的 xpath、类、值来查找查找按钮,但没有成功。请您指导我正确的方向。(目前我还没有给出断言和 EC 库,但我期待下面的简单代码可以工作)。

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()
driver.get("https://www.lowes.com/store/")
search_box = driver.find_element_by_id("search-box")
search_box.send_keys(28262)
find_button = driver.find_element_by_xpath('//*[@id="storeSearch"]/div/div/span/input')
find_button.click()
4

1 回答 1

0

等一下再试一次:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()
driver.get("https://www.lowes.com/store/")
search_box = driver.find_element_by_id("search-box")
search_box.send_keys(28262)
    **put wait here**
    find_button = driver.find_element_by_xpath('//*[@id="storeSearch"]/div/div/span/input')
    **put wait here** 
    find_button.click()
于 2020-01-01T11:26:55.097 回答