2016-05-31 177 views
0

我無法在IE瀏覽器中使用Selenium Web驅動程序單擊單選按鈕。無法點擊單選按鈕Internet Explorer

的HTML如下:

<TD class=PlainText> 
<INPUT onclick="javascript: ShowHideInvoicePanel();setTimeout('__doPostBack(\'ctl00$cphClaimFlow$tabcontainerClaimFlow$tabFulfillment$Shipping$rdoYesFindMyPhone\',\'\')', 0)" id=ctl00_cphClaimFlow_tabcontainerClaimFlow_tabFulfillment_Shipping_rdoYesFindMyPhone type=radio value=rdoYesFindMyPhone name=ctl00$cphClaimFlow$tabcontainerClaimFlow$tabFulfillment$Shipping$phoneanswer> 
<LABEL for=ctl00_cphClaimFlow_tabcontainerClaimFlow_tabFulfillment_Shipping_rdoYesFindMyPhone>Yes</LABEL> 
<INPUT onclick="javascript: ShowHideInvoicePanel();setTimeout('__doPostBack(\'ctl00$cphClaimFlow$tabcontainerClaimFlow$tabFulfillment$Shipping$rdoNoFindMyPhone\',\'\')', 0)" id=ctl00_cphClaimFlow_tabcontainerClaimFlow_tabFulfillment_Shipping_rdoNoFindMyPhone type=radio value=rdoNoFindMyPhone name=ctl00$cphClaimFlow$tabcontainerClaimFlow$tabFulfillment$Shipping$phoneanswer> 
<LABEL for=ctl00_cphClaimFlow_tabcontainerClaimFlow_tabFulfillment_Shipping_rdoNoFindMyPhone>No</LABEL> 

下面是我的代碼:要顯示

WebDriverWait waitForErasePhnYesRadio=new WebDriverWait(driver, timeOut); 
    WebElement elementErasePhnYesRadio= waitForErasePhnYesRadio.until(ExpectedConditions.elementToBeClickable(By.id("ctl00_cphClaimFlow_tabcontainerClaimFlow_tabFulfillment_Shipping_rdoYesFindMyPhone"))); 
    elementErasePhnYesRadio.click(); 
    logger.info("Clicked on Yes button of erase phone script"); 

    if(elementErasePhnYesRadio.isSelected()==false){ 
     System.out.println("is radio btn selected 1 : "+elementErasePhnYesRadio.isSelected()); 
     elementErasePhnYesRadio.click(); 
     System.out.println("is radio btn selected 2 : "+elementErasePhnYesRadio.isSelected()); 
    } 
    System.out.println("is radio btn selected 3 : "+elementErasePhnYesRadio.isSelected()); 

我已經加入等待語句,因爲我在等待來回單選按鈕。代碼正在執行,不會顯示錯誤或異常。

以下輸出顯示控制檯:

INFO [main] (ShippingPage.java:45) - Clicked on Yes button of erase phone script 
is radio btn selected 1 : false 
is radio btn selected 2 : false 
is radio btn selected 3 : false 

回答

0

我沒有看到用引號括起來的ID .....請即得。

JavascriptExecutor js = (JavascriptExecutor)driver; 
Js.executeScript("document.getElementById('ctl00_cphClaimFlow_tabcontainerClaimFlow_tabFulfillment_Shipping_rdoYesFindMyPhone').checked = true;"); 

嘗試使用JS執行和See this link硒醫生說上面的代碼,鼠標應該不叮無縫的,而腳本執行,因爲IE是完全依賴於本地事件。

最後有時可能會發生this

+0

它爲我工作......謝謝:D –

0
driver.findElement(By.id("ctl00_cphClaimFlow_tabcontainerClaimFlow_tabFulfillment_Shipping_rdoYesFindMyPhone")).click(); 
+0

此代碼搜索與給定的ID元素並點擊它 –