请帮助我尝试在离子输入中定位文本区域。该系统是使用离子应用程序构建的
硒代码:
element = Util.findElementByCss("textarea[class = 'app-font-input ng-pristine ng-valid ng-touched']", driver);
Util.sendKeys(element, sSubjectiveSympton, driver, wait);
元素在系统中的位置:
<ion-label class="label label-md">
<textarea charset="utf8" class="app-font-input ng-untouched ng-pristine ng-valid" type="text" ng-reflect-maxlength="2000" ng-reflect-name="2" ng-reflect-model="" id="2" maxlength="2000">
</textarea>
</ion-label>
错误:
Couldn't find Element error: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"textarea[class = 'app-font-input ng-pristine ng-valid ng-touched']"}
(Session info: chrome=67.0.3396.99)
(Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:28.403Z'
System info: host: 'BWSSWDMOLE', ip: '10.60.40.249', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.35.528161 (5b82f2d2aae0ca..., userDataDir: C:\Users\DMaleka\AppData\Lo...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 67.0.3396.99, webStorageEnabled: true}
Session ID: 8f52f4bf2a81b44ca90094ee8fe3a0d7
*** Element info: {Using=css selector, value=textarea[class = 'app-font-input ng-pristine ng-valid ng-touched']}
答案 0 :(得分:0)
根据您的元素定位器
<ion-label class="label label-md">
<textarea charset="utf8" class="app-font-input ng-untouched ng-pristine ng-valid" type="text" ng-reflect-maxlength="2000" ng-reflect-name="2" ng-reflect-model="" id="2" maxlength="2000">
</textarea>
</ion-label>
您的css选择器值不同于上面的html和代码。
html中的值是 app-font-input ng-untouched ng-pristine ng-valid
但是代码上的值是 app-font-input ng-pristine ng-valid ng-touched
在下面的代码中插入正确的CSS值
element = Util.findElementByCss("textarea[class = 'app-font-input ng-untouched ng-pristine ng-valid']", driver);
Util.sendKeys(element, sSubjectiveSympton, driver, wait);
答案 1 :(得分:0)
在xpath下使用:
//textarea[@class='app-font-input ng-untouched ng-pristine ng-valid']
找不到元素错误:org.openqa.selenium.NoSuchElementException
根据您的情况,您需要根据网站和元素实施隐式等待或显式等待。