[英]org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element error using Selenium through Java
How to write selenium test automation for this html.如何为此 html 编写 selenium 测试自动化。 At Below There are html,java code and error.
在下面有html,java代码和错误。 I am doing Everthing but i don't click to comboBox.
我正在做任何事情,但我不点击组合框。
html code html代码
<div _model-c4 class="blenderFive yellow">
<input _model-c4 type="checkbox" id="control-model-m-1">
<label _model-c4 for="control-model-m-1" class>
::before
<span _model-c4 class="ppd-1"> Bathroom</span>
::after
</label>
</div>
java-selenium code: java硒代码:
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath(""));
WebElement temp20 = driver.findElement(By.xpath("//quick-checkbox/div/div/label"));
temp20.click();
Error错误
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//div/input[@id='control-model-m-1']"}
(Session info: chrome=79.0.3945.88)
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.9.0', revision: '698b3178f0', time: '2018-02-05T14:56:13.134Z'
System info: host: 'STJ8CG445050D', ip: '10.134.12.134', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_231'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 79.0.3945.88, chrome: {chromedriverVersion: 79.0.3945.36 (3582db32b3389..., userDataDir: D:\Users\home\AppData\Lo...}, goog:chromeOptions: {debuggerAddress: localhost:44210}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: r4413edasdafq313405d909cd123
*** Element info: {Using=xpath, value=//div/input[@id='control-model-m-1']}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:160)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:371)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:473)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363)
at sampleTEST.expressTest.bundle(expressTest.java:131)
at sampleTEST.expressTest.main(expressTest.java:15)
尝试通过这个 Xpath 搜索它:
$x("//input[contains(@id,'control-model-m-1')]")
To click()
on the <input>
tag associated with the element with text as Bathroom you need to induce WebDriverWait for the element_to_be_clickable()
and you can use either of the following Locator Strategies :要在与文本为Bathroom的元素相关联的
<input>
标签上click()
,您需要为element_to_be_clickable()
引入WebDriverWait ,您可以使用以下任一定位器策略:
xpath
: xpath
:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='blenderFive yellow']//span[normalize-space()='Bathroom']//preceding::input[1]"))).click();
You can try to click element by javascript.您可以尝试通过 javascript 单击元素。 This is code:
这是代码:
JavascriptExecutor je = (JavascriptExecutor)driver;
JavascriptExecutor je = (JavascriptExecutor)driver;
je.executeScript("arguments[0].click();", element);
je.executeScript("arguments[0].click();", element);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.