首页 > 解决方案 > 尝试在 webelement 中选择元素,但我得到 object is not callable 错误

问题描述

我一直在尝试选择 web 元素内的元素,我得到:“TypeError:'WebElement' 对象不可调用”

def get_engagmet(driver, time, a):
    engagment = {}
    body_element = driver.find_elements_by_xpath("//div[@class='_5pcr userContentWrapper']")
    link = body_element[a].find_element_by_xpath(".//a[@rel='theater']")
    print("this is link")
    print(link("href"))
    time.sleep(3)

无论如何,这应该有效。

标签: pythonfunctionselenium-webdriver

解决方案


代替

print(link("href"))

print(link.get_attribute("href"))

PS 此外,您可能会分享您尝试抓取的 URL,以检查您的 XPath 是否正确匹配。


推荐阅读