gpt4 book ai didi

javascript - 为什么无法使用 selenium webdriver 选择单选按钮?

转载 作者:太空宇宙 更新时间:2023-11-04 11:38:07 25 4
gpt4 key购买 nike

操作系统:Windows 7 Selenium 版本:3.3.1,浏览器:火狐浏览器版本:47.0.2(64位)

Html Code:



<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>

当我尝试选择第一个单选按钮时,使用 cssSelectorxpath 和所有定位器失败

driver.findElement(By.cssSelector("#passwordRadios1")).click();

Error

Test Failed
2
Exception in thread "main" org.openqa.selenium.WebDriverException: Element <input name="passwordRadios" id="passwordRadios1" class="password-radio" value="guest" type="radio"> is not clickable at point (168, 431.83331298828125). Other element would receive the click: <div class="loader-overlay" style="opacity:0.9;"></div>
Command duration or timeout: 560 milliseconds
Build info: version: 'unknown', revision: '5234b32', time: '2017-03-10 09:00:17 -0800'
System info: host: 'TWVEN-DES-05', ip: '172.16.24.53', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=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}]
Session ID: a692e880-f284-47af-9a20-1bcf60d76e63
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)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:638)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
at tesPack.Test1Class.main(Test1Class.java:76)

谁能帮帮我...

最佳答案

尝试下面的代码。

driver.get("file:///C:/Users/Jainish.M.Kapadia/Desktop/aaa.html");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

driver.findElement(By.id("inputEmail")).sendKeys("test@gmail.com");

WebDriverWait wait = new WebDriverWait(driver, 7);
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//input[@id='passwordRadios1']"))));

WebElement no = driver.findElement(By.xpath("//input[@id='passwordRadios1']"));
if(!no.isSelected())
{
no.click();
}

关于javascript - 为什么无法使用 selenium webdriver 选择单选按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43061989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com