Python 如何单击没有ID的元素

Python 如何单击没有ID的元素,python,html,selenium,Python,Html,Selenium,我有下面的HTML,我正在尝试单击名为tasks的元素 *<td class="class_popup2_menuitem_caption" unselectable="on" nowrap="">Tasks</td>* 然而,我得到了以下回应 ElementNotVisibleException:消息:元素不可交互 我正在尝试使用selenium和java展示此异常的根本原因。请尝试用python实现。 ElementNotVisibleException:Messa

我有下面的HTML,我正在尝试单击名为tasks的元素

*<td class="class_popup2_menuitem_caption" unselectable="on" nowrap="">Tasks</td>*
然而,我得到了以下回应

ElementNotVisibleException:消息:元素不可交互

我正在尝试使用selenium和java展示此异常的根本原因。请尝试用python实现。

ElementNotVisibleException:Message:element not Interactivatable(元素不可交互)是在找到元素时产生的,但您无法与它交互。例如,您可能无法单击或发送密钥

这可能有几个原因:

使其可交互的策略(取决于具体情况)

1。等待元素可见/可单击

2。滚动,直到元素在显示屏中

3。使用javascript直接与DOM交互


4。执行任何其他必要的操作,并可能在之后等待。

欢迎使用StackOverflow。请按照您创建此帐户时的建议,阅读并遵循帮助文档中的发布指南。适用于这里。在您发布MCVE代码并准确描述问题之前,我们无法有效地帮助您。我们应该能够将您发布的代码粘贴到文本文件中,并重现您描述的问题。我知道您试图提供帮助,但发布的答案使用的语言与OP要求的语言不同。
x = driver.find_element_by_xpath("//div/table/tbody//td[contains(text(), 'Tasks')]") 
x.click()
 - The element is not visible / not displayed The element is off screen
 - The element is behind another element or hidden Some other action
 - needs to be performed by the user first to enable it.
WebDriverWait wait = new WebDriverWait(driver, timeout);
wait.until(ExpectedConditions.visibilityOf(element)); 
wait.until(ExpectedConditions.elementToBeClickable(element));
Actions action = new Actions(driver);
action.moveToElement(element);
JavascriptExecutor javascript = (JavascriptExecutor) driver;
javascript.executeScript("var element = document.querySelector('locator'); element.value = 'whatever';")