首页 > 解决方案 > Python3 Whatsapp + Selenium - “点击”对象不可调用

问题描述

我无法在 whatsapp 中点击人名。

The error is: TypeError: 'WebElement' object is not callable.

My code:

person = 'Tom'

click = driver.find_element_by_xpath(f'//span[contains(@title,"{person}")]')
click()

I also tried

click = driver.find_element_by_xpath(f'//span[contains(@title,"{person}")]/parent::*')

标签: python-3.xselenium

解决方案


该语法click()不起作用,因为click它是一个 webElement,而不是一个函数。它应该像

element = driver.find_element_by_xpath(f'//span[contains(@title,"{person}")]')
element.click()

推荐阅读