【发布时间】:2017-09-19 06:02:01
【问题描述】:
我正在尝试制作一个自动脚本机器人来查找特定项目并将该项目添加到用户购物车等。现在我正忙着让 python 从下拉菜单中选择大小。
我还使用了 WebDriverWait 函数,因为它给了我一个 element not found 错误,所以我认为它的 'size' 元素还没有加载。
Python 也抛出了这个错误
"TypeError: 'str' 对象不可调用"
下面也是我引用的用于从中提取信息的 html 代码的图片。也将感谢任何关于更好执行的建议。
from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
# Open chrome web browswer and directs to supreme.com
browser = webdriver.Chrome()
browser.get('http://www.supremenewyork.com/shop/all')
#Find specific item
browser.find_element_by_xpath('//*
[@id="container"]/article[14]/div/a/img').click()
#Wait for element to load
pause = WebDriverWait(browser,10).until(
EC.visibility_of_any_elements_located(By.ID('size'))
)
# Select size
Select = Select(browser.find_element_by_id('size'))
Select.select_by_visible_text("Large")
【问题讨论】:
-
您可能需要单击定位器,因为在单击尺寸下拉菜单之前不会启用这些选项。此外,您页面的中间状态可能会导致此页面失败,因为您建议购买的文章已经售罄
-
所以我错过了调用 .click() 函数吗?
标签: python selenium scripting bots selenium-chromedriver