我有一个Selenium网络驱动程序脚本,它只访问一个web元素(文本框)并将其值设置为某个值。
我使用的是ChutzPath,因为它在后端使用了PhantomJS浏览器。
但每次执行脚本时,都会显示以下错误。
T
Result Message:
Test method Test_Project_with_Selenium.UnitTest1.BrowseTheWeb threw exception:
OpenQA.Selenium.NoSuchElementException: Error Message => 'Unable to find element with id 'inputEl''
***caused by Request => {"headers":{"Accept":"application/json, image/png","Connection":"Close","Content-Length":"47","Content-Type":"application/json;charset=utf-8","Host":"localhost:42982"},"httpVersion":"1.1","method":"POST","post":"{\"using\":\"id\",\"value\":\"textfield-1042-inputEl\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/01225660-1a45-11e3-8ea4-eff85782779d/element"}
Result StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementById(String id)
at Test_Project_with_Selenium.UnitTest1.BrowseTheWebClient() in c:\Users\XYZ\Documents\Visual Studio 2012\Projects\ProjectName\Test_Project_with_Selenium\UnitTest1.cs:line 19***
答案 0 :(得分:2)
不确定这是否是这种情况,因为问题不是很具体,但我遇到的一件事是PhantomJS 1.9.7需要在该位置使用HTTP方案。
因此,如果您要导航localhost:42982/element
,则应指定您要导航到http://localhost:42982/element
的驱动程序。
答案 1 :(得分:1)
关闭袖口,你可能遇到Selenium查询页面后加载元素的问题,你可以使用waitfor.js
https://github.com/ariya/phantomjs/blob/master/examples/waitfor.js
或者可能这样:
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS)
或者您要查找的ID位于框架/ iframe内,在这种情况下您需要使用
Driver.SwitchTo().Frame("frameIdentifier");