簡體   English   中英

為什么我沒有使用selenium webdriver選擇單選按鈕?

[英]Why am failing to select radio button using selenium webdriver?

操作系統:Windows 7 Selenium版本:3.3.1,瀏覽器:Firefox瀏覽器版本: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();

錯誤

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();
}

嘗試使用JavascriptExecutor單擊元素,如下所示:

WebElement element = driver.findElement(By.xpath("//input[@id='passwordRadios2']"));
((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM