【问题标题】:selenium python error 'dict' object has no attribute 'click'selenium python错误'dict'对象没有属性'click'
【发布时间】:2018-06-04 06:14:56
【问题描述】:
if href.startswith("https://store.steampowered"):
    browser.get(href)

    if browser.current_url.startswith("https://store.steampowered.com/agecheck"):
        area = browser.find_element_by_id("agecheck_form")
        location_field = area.find_element_by_id("ageYear")

        for option in location_field.find_elements_by_tag_name("option"):
            if int(option.text) == 1999:
                option.click()
                break

            enter = browser.find_element_by_xpath('//*[@id="agecheck_form"]/a')
            enter.location_once_scrolled_into_view.click()

我编写这段代码的目的是去 Steam 游戏页面获取游戏的价格。如果它遇到年龄检查墙,它会运行我上面的代码。

https://store.steampowered.com/agecheck/app/489830/

我的问题是无论我如何格式化输入按钮上的点击事件,它都会给我错误:'dict' object has no attribute 'click'

我已经搜索过什么是字典,但仍然很困惑。 我怀疑这个问题可能与我的选项循环有关。

【问题讨论】:

    标签: python selenium selenium-webdriver


    【解决方案1】:

    location_once_scrolled_into_view 返回字典,webelementxy 坐标。去掉就行,selenium 会自动滚动到点击前的webelement

    【讨论】:

    • 非常感谢!我知道这会很简单/愚蠢
    • 我有同样的问题,我不得不降级 selenium 才能让它工作。您能否详细说明您的解决方案,我不完全理解
    • @Ash 解决方案是删除 location_once_scrolled_into_view 并单击元素,我不确定我可以添加什么。
    猜你喜欢
    • 2022-01-14
    • 1970-01-01
    • 1970-01-01
    • 2012-10-06
    • 2015-08-05
    • 2018-09-28
    • 2022-10-24
    • 2022-01-27
    • 2012-06-28
    相关资源
    最近更新 更多