【问题标题】:Selenium not giving whats inside a class?Selenium 没有在课堂上提供什么?
【发布时间】:2021-05-24 12:09:02
【问题描述】:
PATH = "D:\CDriver\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get('https://www.se.com/ww/en/about-us/careers/job-details/inside-sales-associate/006ZMV')
TITLE = driver.find_element_by_class_name('sdl-application-job-details__job-title')
print(TITLE)
driver.quit()

我有所有需要的导入,我只是想把它们排除在外。

当我运行这个时,输出应该是:Inside Sales Associate

但它给了我这个:<selenium.webdriver.remote.webelement.WebElement, 会话和元素代码。

我需要做什么才能让它打印它应该打印的东西。我试过by_tag_name('h1.sdl-application-job-details__job-title'),但结果完全相同。

【问题讨论】:

    标签: html python-3.x selenium


    【解决方案1】:

    Selenium 中有一个内置的title 方法。您可以在 driver object 而不是 web element 上调用该方法。

    代码:

    driver.get('https://www.se.com/ww/en/about-us/careers/job-details/inside-sales-associate/006ZMV')
    driver.title
    print(driver.title)
    

    或者如果你想在任何 web 元素中检索文本,你可以这样做:

    class_value = driver.find_element(By.CSS_SELECTOR, "h1[class$='sdl-application-job-details__job-title']").text
    print(class_value)
    

    【讨论】:

      【解决方案2】:

      find_element 方法返回网页元素。只要通过print(TITLE.text)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-04-04
        • 2021-12-22
        • 2020-08-30
        • 2016-11-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-07-12
        相关资源
        最近更新 更多