如何为此HTML编写硒测试自动化。在下面有html,java代码和错误。我在做Everthing,但我没有单击comboBox。
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-硒代码:
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath(""));
WebElement temp20 = driver.findElement(By.xpath("//quick-checkbox/div/div/label"));
temp20.click();
错误
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)
答案 0 :(得分:0)
尝试通过此Xpath搜索它:
$x("//input[contains(@id,'control-model-m-1')]")
答案 1 :(得分:0)
要在与文本为浴室的元素相关的click()
标签上的<input>
上,您需要为{{1}诱导 WebDriverWait },您可以使用以下任一Locator Strategies:
element_to_be_clickable()
:
xpath
答案 2 :(得分:0)
您可以尝试通过javascript单击元素。这是代码:
JavascriptExecutor je =(JavascriptExecutor)驱动程序;
je.executeScript(“ arguments [0] .click();”,element);