如何避免“元素当前不可见,因此可能无法与之交互"Selenium 网络驱动程序 [英] How I can avoid "Element is not currently visible and so may not be interacted with " Selenium Webdriver

查看:24
本文介绍了如何避免“元素当前不可见,因此可能无法与之交互"Selenium 网络驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 selenium webdriver 2.210 + JAVA 进行测试.我有一个示例代码用于选择 gmail 中的所有邮件.但是当我尝试放置时,代码会引发元素当前不可见,因此可能无法与之交互"错误通过 webdriver 获取 URL 后延迟 5 秒.是否可以使此代码延迟工作?

Am using selenium webdriver 2.210 + JAVA for testing.I have a sample code for selecting all mails in gmail.But the code throws an "Element is not currently visible and so may not be interacted with" error when i tries to put a 5sec delay after getting URL through webdriver.Is it possible to make this code working with delay?

    driver.get("https://mail.google.com/mail/u/0/?shva=1#all");
        delay(5);  ////*......Working fine without this...........*////
    driver.switchTo().frame(driver.findElement(By.id("canvas_frame")));
driver.findElement(By.xpath("//div[@class = 'T-Jo-auh']")).click();

提前致谢

推荐答案

你确定你在寻找正确的元素吗?我遇到了类似的问题,结果页面上有两个相似的元素,一个可见,另一个不可见.FindElement 函数正在返回不可见的那个.

Are you sure you're looking at the right element? I had a similar problem and it turned out there were two similar elements on the page, one visible and the other not. The FindElement function was returning the one that wasn't visible.

我通过使用 FindElements 而不是 FindElement 解决了这个问题,然后使用 Linq 提取可见的那个.

I solved this by using FindElements instead of FindElement and then using Linq to extract the one that was visible.

这篇关于如何避免“元素当前不可见,因此可能无法与之交互"Selenium 网络驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆