是否通过将 WebElement 的变量传递到另一个“Actions”的构造函数来调用 webElement?班级?
System.setProperty("webdriver.chrome.driver","D:\\ChromeDriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.amazon.com/");
Actions a = new Actions(driver);
WebElement move = driver.findElement(By.cssSelector("a[id='nav-link-accountList']"));
a.moveToElement(move).build.perform();
最后一步没看懂。
System.setProperty("webdriver.chrome.driver","D:\\ChromeDriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.amazon.com/");
Actions a = new Actions(driver);
WebElement move = driver.findElement(By.cssSelector("a[id='nav-link-accountList']"));
a.moveToElement(move).build.perform();
I didn't understand the last step.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案肯定是否定的。
您可以通过调试您编写的测试脚本来看到这一点
它将获取该元素的“按定位器”数据(在本例中为 By.cssSelector("a[id='nav-link-accountList']") )添加经过它到 moveToElement() 函数。
笔记:
试想一下,如果每次在某个地方使用“WebElement”时都调用它,那么对于驱动程序来说,相同的逻辑条件也将成立。这意味着每当您使用“driver.findElement”时,它都会转到第一行代码“WebDriver driver = new ChromeDriver();”每次使用“driver.findElement”方法时它都会打开新的浏览器
The answer is definitely not.
You can see this by debugging the test script you wrote
It will take that element's 'By locator' data (In this case it is By.cssSelector("a[id='nav-link-accountList']") ) add pass it to the moveToElement() function.
Note:
Just imagine if 'WebElement' being called every time when it is used somewhere the same logical condition would have been true for the driver as well. That means whenever you would use 'driver.findElement' It would go to the first line of code that is 'WebDriver driver = new ChromeDriver();' and it would open new browser each time you use 'driver.findElement' method