Javascript 未知错误:无法聚焦元素
以下是输入字段代码:Javascript 未知错误:无法聚焦元素,javascript,angularjs,selenium,protractor,Javascript,Angularjs,Selenium,Protractor,以下是输入字段代码: <span ng-if="cell.state != 'edit_mode'" class="ng-scope"> <span ng-class="{'with-right-padding' : cell.input_type === 'auto_complete'}" class="value-cell ng-binding">10 </span> <!-- ngIf: cell.valid ===
<span ng-if="cell.state != 'edit_mode'" class="ng-scope">
<span ng-class="{'with-right-padding' : cell.input_type === 'auto_complete'}" class="value-cell ng-binding">10 </span>
<!-- ngIf: cell.valid === false && server_side_errors_present -->
</span>
问题是当replay my code click事件有效但发送密钥无效时
下面是我得到的错误:
Failures:
1) Customer Add a estimate
Message:
Failed: unknown error: cannot focus element
(Session info: chrome=48.0.2564.109)
(Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 26 milliseconds
Build info: version: '2.51.0', revision: '1af067d', time: '2016-02-05 19:15:17'
System info: host: 'Bala-PC', ip: , os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_71'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4), userDataDir=C:\Users\Bala\AppData\Local\Temp\scoped_dir4612_146}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=48.0.2564.109, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: e5f4a8ca6076e1cafbcc366f45680dd1
Stack:
UnknownError: unknown error: cannot focus element
(Session info: chrome=48.0.2564.109)
(Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 26 milliseconds
Build info: version: '2.51.0', revision: '1af067d', time: '2016-02-05 19:15:17'
System info: host: 'Bala-PC', ip: '192.168.1.22', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_71'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4), userDataDir=C:\Users\Bala\AppData\Local\Temp\scoped_dir4612_146}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=48.0.2564.109, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
请有人给我答案
var element = driver.findElement(By.xpath("//div[@class='animate']/div/div[2]/span[2]/section/div/div/section/div/div/div/span/section/div[2]/div/div/section/div[2]/section[1]/table/tbody[1]/tr[4]/td[3]/span/span[1]/span"))
driver.executeScript("arguments[0].setAttribute('value', arguments[1])", element, '10');
这可能会奏效。这基本上是使用SeleniumWebDriver中的执行脚本方法。。。如果这不起作用,我真的建议尝试使用xpath以外的方法测试字段。我认为困难在于专注于字段上面的答案使用javascript,如果输入或其父项具有需要触发的事件处理程序,则将无法工作,例如,在使用提前键入控件的情况下 为了修复它,我们可以使用Selenium操作:
Actions assigner = new Actions(webdriver);
assigner.moveToElement(webelement);
assigner.click();
assigner.sendKeys("<your value>");
assigner.build().perform();
Actions assigner=新操作(webdriver);
转让人.移动元素(webelement);
assigner.click();
转让人。发送密钥(“”);
assigner.build().perform();
您是否正在使用最新的selenium驱动程序?chrome驱动程序的某些版本也不具备发送键功能。是的,我使用的是最新版本。我现在该怎么办?。但在其他文本框中,它可以工作。您在FF和IE中尝试过吗?“其他文本框”的元素类型是否相同?它实际上不是文本框。。。我的web应用程序是基于Angularjs的。当你们点击回车键或双击该字段时,它会给你们一个文本区域,你们可以在其中输入一个值……下面是我从firebug中获取的该字段的代码片段。。。请勾选2另一个文本框实际上应该是input或textarea,查找它。
Actions assigner = new Actions(webdriver);
assigner.moveToElement(webelement);
assigner.click();
assigner.sendKeys("<your value>");
assigner.build().perform();