【问题标题】:Expand Button Selenium Python展开按钮 Selenium Python
【发布时间】:2021-06-17 15:10:20
【问题描述】:

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

# FIRST - GET THE WEBPAGE
url = "https://op.europa.eu/en/web/who-is-who/organization/-/organization/EP/EP"
driver = webdriver.Chrome("C:/Users/XXX/Downloads/chromedriver_win32/chromedriver.exe")
driver.get(url)

# SECOND - CLICK THE BUTTONS
test = driver.find_element_by_css_selector("op-icon op-icon-more tree-hitarea").click()
print(test)

现在我的问题是如何在 selenium 中使用 .click() 来扩展这个按钮/图标。尽管我发现了一些类似的问题,但这绝不是关于图标的。我很迷茫

【问题讨论】:

    标签: python selenium web-scraping icons expand


    【解决方案1】:
    driver.find_element_by_css_selector("span.op-icon.op-icon-more.tree-hitarea").click()
    

    css 选择器中的多个类名或由 . 分隔的。

    【讨论】:

      【解决方案2】:

      要展开按钮,您需要使用元素的 xpath,然后单击它。 从 chrome 安装 chrome 插件 XPath Helper,然后在刷新后单击插件,然后 shift + 单击您需要的元素。 之后使用 driver.find_element_by_xpath().click()

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-05-21
        • 2021-03-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-15
        • 2023-01-14
        • 2014-02-16
        相关资源
        最近更新 更多