将文本输入文本框后无法单击单选按钮..为什么光标始终在文本框中?

时间:2017-03-30 10:41:25

标签: java selenium-webdriver

HTML代码:

<div class="radio">
<input id="passwordRadios1" class="password-radio" type="radio" value="guest" name="passwordRadios">
<input type="hidden" value=" " name="_D:passwordRadios">
<label for="passwordRadios1"> No (you can save your details later)</label>
</div>
<div class="form-inline">
<div class="radio">
<input id="passwordRadios2" class="password-radio" type="radio" value="register" name="passwordRadios">
<input type="hidden" value=" " name="_D:passwordRadios">
<label class="radio-inline" for="passwordRadios2">Yes, my password is:</label>
</div>
<div class="form-group">
<label class="sr-only" for="inputPassword">Password</label>
<input id="inputPassword" class="form-control fixed-width" type="password" value="" placeholder="Enter your password*" name="password" onblur="textboxValidator(id);">
<input type="hidden" value=" " name="_D:password">

在第二行显示错误

 WebElement checkBox = driver.findElement(By.cssSelector("input[value='guest']"));
 checkBox.click();

错误:

  

线程中的异常&#34; main&#34; org.openqa.selenium.WebDriverException:元素在点(168,431.83331298828125)处不可点击。其他元素将收到点击:       命令持续时间或超时:78毫秒       建立信息:版本:&#39;未知&#39;,修订版:&#39; 5234b32&#39;,时间:&#39; 2017-03-10 09:00:17 -0800&#39;       系统信息:主持人:&#39; TWVEN-DES-05&#39;,ip:&#39; 172.16.24.53&#39;,os.name:&#39; Windows 7&#39;,os.arch: &#39; amd64&#39;,os.version:&#39; 6.1&#39;,java.version:&#39; 1.8.0_121&#39;       驱动程序信息:org.openqa.selenium.firefox.FirefoxDriver       Capabilities [{applicationCacheEnabled = true,rotate = false,handlesAlerts = true,databaseEnabled = true,version = 47.0.2,platform = WINDOWS,nativeEvents = false,acceptSslCerts = true,webStorageEnabled = true,locationContextEnabled = true,browserName = firefox,takesScreenshot = true,javascriptEnabled = true,cssSelectorsEnabled = true}]       会议ID:4857ae27-ea9a-4c3c-ba3d-e04148e04e45           at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)           at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)           at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)           at java.lang.reflect.Constructor.newInstance(Unknown Source)           在org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)           在org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)           在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:638)           在org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274)           在org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)           在tesPack.Test1Class.main(Test1Class.java:43)

1 个答案:

答案 0 :(得分:0)

我以前见过这样的东西,在我看来是因为元素本身在浏览器窗口中不可见,并且滚出框架。在点击之前尝试添加actions.moveToElement(checkBox)