java - Java Selenium“findElement”找不到现有对象
问题描述
昨天我的问题解决后(见下面的链接),新的问题又出现了。首先,上述问题的解决方案仅适用于 IE。当我尝试使用相同的代码来馈送 chrome 或 firefox 时(当然,驱动程序除外),我会收到一开始的错误消息(在我降级 IEDriverServer 之前)。见链接。
Eclipse Java Selenium 无法连接到 localhost
第二。当我使用 findelement 函数时不会发生。错误消息“无法找到元素”。但是,这个元素是存在的。这里应该控制的页面。
这个问题已经经常被要求,但不幸的是答案对我没有帮助。一种解决方案是(因为 findelement 比浏览器更快)安装以下延迟。驱动程序管理()。超时()。隐式等待(5,TimeUnit.SECONDS);
另一种解决方案是搜索 id 或 xpath 而不是 name(这就是 name 和 id 在下面列为 findelement 的原因)。到目前为止没有成功。没有在字段中输入任何提到的键(密码和名字等,我已经尝试过)。
以下是最接近我的问题但对我没有帮助的文章。 没有这样的元素异常 | 互联网浏览器。
相同的 CSS 选择器在 Internet Explorer 中不起作用,但在 Firefox 中起作用
反正。IE 将打开,但不会填充其他浏览器和元素。这里的代码和错误信息。
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.grid.selenium.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.TimeUnit;
public class firefoxöffner {
public static void main(String[] args) throws IOException, URISyntaxException {
System.setProperty("webdriver.gecko.driver","./geckodriver");
String service = "D://IEDriverServer.exe";
System.setProperty("webdriver.ie.driver", service);
InternetExplorerDriver driver = new InternetExplorerDriver();
driver.get("https://accounts.google.com/signup/v2/webcreateaccount?flowName=GlifWebSignIn&flowEntry=SignUp");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
WebElement myDynamicElement = driver.findElement(By.id("lastName"));
driver.findElement(By.id("lastName")).sendKeys("B");
driver.findElement(By.name("lastName")).sendKeys("A");
}
}
已启动 InternetExplorerDriver 服务器(64 位) 3.8.0.0 监听端口 47620 仅允许本地连接 Mai 06, 2018 11:29:28 NACHM。org.openqa.selenium.remote.ProtocolHandshake createSession 信息:检测到方言:线程“main”中的 W3C 异常 org.openqa.selenium.NoSuchElementException:无法使用 css 选择器 == #lastName 找到元素
再次感谢。
解决方案
如果您使用 Java + Selenium 进行 Web 界面测试,我建议您使用NoraUi开源框架。
该框架管理 IE webdriver、Chrome webdriver 和 FF webdriver。
推荐阅读
- angular - 我有大约 30 个社交链接字段来获取每个我想使用 formArray 构建的 url
- c++ - 需要使用递归c ++计算算术级数的总和
- angular - 未定义标识符“已提交”
- javascript - 如何在javascript中将封闭的双引号转换为单引号?
- visual-studio - API Gateway 的 SAM 模板在 Visual Studio 中存在错误(作为无服务器应用程序解决方案的一部分)
- flask - 使用 pytest 测试烧瓶应用程序时,如何解决身份验证标头/cookie 丢失问题?
- css - CSS - 带阴影的 ZigZag 右边框
- aop - AspectJ 中代码内和代码内指示符之间的区别
- api - 使用 JSON Web Token (JWT) 进行身份验证和授权
- r - R 绘制数据集子集的核密度(以 char 变量为条件)