在chrome中运行我的测试并在FF中运行edge时,出现无法聚焦元素错误,它工作正常。我尝试过发布决议,但无济于事。我不确定该怎么做。希望有人在那里可以提供帮助。提前致谢。
driver.findElement(By.linkText("Add")).click();
List <WebElement> groups = new Select(driver.findElement(By.xpath("/html/body/div[1]/section/div/article/form/fieldset/div[3]/div[2]/div/div/div[1]/select"))).getOptions();
groups.get(3).click();
JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement groupRole = driver.findElement(By.xpath("/html/body/div[1]/section/div/article/form/fieldset/div[3]/div[2]/div/div/div[2]/label[2]"));
js.executeScript("arguments[0].click();", groupRole);
driver.findElement(By.xpath("/html/body/div[1]/section/div/article/form/fieldset/div[3]/div[2]/div/div/div[2]/label[2]")).sendKeys(" ");
// Check to see if the user should be made active and set active checkbox to on if value in file is "active"
if (activeFlag.equals("active"))
{
driver.findElement(By.xpath("/html/body/div[1]/section/div/article/form/fieldset/div[3]/div[1]/div[1]/div/div/input")).sendKeys(" ");
}
// If the user role is to be admin then set the Site role to Administrator
if (userLevel.equals("admin"))
{
List <WebElement> roles = new Select(driver.findElement(By.name("community_role"))).getOptions();
roles.get(1).click();
}
这是堆栈跟踪:
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot focus element
(Session info: chrome=47.0.2526.106)
(Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 10.0 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 81 milliseconds
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: host: 'Janet-PC', ip: '192.168.56.1', os.name: 'Windows 8.1', os.arch: 'x86', os.version: '6.3', java.version: '1.7.0_80-ea'
Session ID: 0a9dbd54a81a42a4178b25b95bb14f63
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=WIN8_1, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=C:\Users\Janet\AppData\Local\Temp\scoped_dir7508_15608}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=47.0.2526.106, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, hasTouchScreen=false, applicationCacheEnabled=false, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:326)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:121)
at Viddler_create_user.createUser.test(createUser.java:244)
at Viddler_create_user.createUser.setUpBeforeClass(createUser.java:126)
at Viddler_create_user.createUser.main(createUser.java:64)
这是另一个堆栈跟踪。尝试单击“提交”按钮而不是活动标志时,实际上出现了错误。我已经完成了将要提供的操作步骤。
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot focus element
(Session info: chrome=47.0.2526.106)
(Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 10.0 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 52 milliseconds
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: host: 'Janet-PC', ip: '192.168.56.1', os.name: 'Windows 8.1', os.arch: 'x86', os.version: '6.3', java.version: '1.7.0_80-ea'
Session ID: f332b496aa54d581c764f7328e770e65
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=WIN8_1, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=C:\Users\Janet\AppData\Local\Temp\scoped_dir2072_18936}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=47.0.2526.106, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, hasTouchScreen=false, applicationCacheEnabled=false, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:326)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:121)
at Viddler_create_user.createUser.test(createUser.java:244)
at Viddler_create_user.createUser.setUpBeforeClass(createUser.java:126)
at Viddler_create_user.createUser.main(createUser.java:64)
码:
Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(By.xpath("/html/body/div[1]/section/div/article/form/input[2]")));
actions.click();
// actions.sendKeys(" ");
actions.build().perform();
sendstacks方法是根据堆栈跟踪的问题。
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:121)
请尝试Actions
上课,首先专注于元素,然后发送所需的键。
Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.click();
actions.sendKeys("SOME DATA");
actions.build().perform();
在chrome和edge中运行测试时,我遇到了无法聚焦元素错误,它工作正常。我尝试了发布的分辨率,但无济于事。我不知道该怎么办。希望有人能帮忙。提前谢谢。 这是堆栈跟踪: 这是另一个堆栈跟踪。实际上,我在尝试单击提交按钮而不是活动标志时出错。我已经完成了我还将提供的操作步骤。 代码:
我尝试了xpath和检查,如下所示
我刚开始学习Selenium,需要使用云中的jenkins机器验证登录网页,该机器没有GUI。我成功地在有UI的系统上运行了脚本。然而,当我将脚本修改为运行headless时,它无法表示无法定位元素。我的脚本如下: 当不使用chrome_options时,python脚本在我的系统上运行良好。但是在将它们添加到无头模式下运行时,它会失败,输出如下: 由于我对Selenium有大约一天的学习时间,我
单击应用程序中的菜单时,它会自动在新选项卡中打开该页面,然后在新选项卡中执行操作 切换到新窗口后无法找到元素 如何单击新打开的选项卡中的元素? 这是salesforce应用程序
下面是selenium找不到元素的代码。 但不知何故,它失败了,对我不起作用。它总是给我以下例外情况:过时的元素引用:元素未附加到页面文档 添加了--GetElementStextList的代码 感谢任何帮助。谢谢