【问题标题】:My selenium says that Element is not currently visible and so may not be interacted with我的硒说元素当前不可见,因此可能无法与之交互
【发布时间】:2016-10-13 08:27:23
【问题描述】:

我尝试单击 ui-popup 上的按钮,但总是失败。 HTML:

网络看起来像这样:

我写道:

driver.find_element_by_xpath('//*[@id="focussuccesstipsclose"]').click()

但它说

'selenium.common.exceptions.ElementNotVisibleException:消息: 元素当前不可见,因此可能无法与之交互'

我在网上找到了许多类似的问题,但它们无法解决我的问题。我是 selenium 的初学者,我们将不胜感激!

【问题讨论】:

  • 请把代码贴在这个帖子里,不要截图。
  • 对不起。第一次提问
  • 已解决。此元素从其父元素中不可见,因此使用: parentElement = driver.find_element_by_xpath('//*[@id="focussuccesstips"]') driver.execute_script('arguments[ 0].style.display="block";',parentElement) driver.find_element_by_xpath('/html/body/div[7]/div/table/tbody/tr[1]/td/button').click()
  • 如果您找到适合您的答案,请将其作为答案发布并接受。也请为未来的读者清理您的问题。

标签: python selenium


【解决方案1】:

当某些其他元素覆盖您要对其执行操作的元素时,就会发生这种情况。 你的情况
driver.find_element_by_xpath('//*[@id="focussuccesstipsclose"]').click()

在此步骤之前检查您是否正在执行任何其他操作,如果是,则检查该操作是否覆盖屏幕上的“focussuccesstipsclose”ID UI,如果是,则 selenium 会说“元素当前不可见,因此可能不可见互动”。

要遇到这种情况,请尝试单击页面上的其他位置,这将删除您的ID 的封面。

当日历覆盖我的元素时,我遇到了这个问题。

【讨论】:

  • 你能做一些检查吗,比如 - 页面有一个名为“focussuccesstipsclose”的 ID。您正在等待足够的时间来加载元素。
【解决方案2】:

使用 javascript 执行器

 WebElement element = driver.findElement(By.xpath("//a[@id='focussuccesstipsclose']"));
 JavascriptExecutor executor = (JavascriptExecutor)driver;
 executor.executeScript("arguments[0].click();", element);

如果显示元素不可见异常则使用 webdriver 等待方法

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-13
    • 2016-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多