0

I am not able to get the radio button clicked using Selenium web driver in IE browser.

The html is as follows:

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

Below is my code:

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

I have added wait statement as I am waiting fro radio button to be displayed. The code is executing and no error or exception is displayed.

Below output is printed in console:

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
Aks.Soms
  • 137
  • 3
  • 13

2 Answers2

0

I don't see Ids enclosed in quotes.....please check that too.

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

try the above code using JS executor and See this link the selenium doc says, mouse should not hover while script execution, since in IE it is completely depend on native events.

Finally sometimes this may happen.

Community
  • 1
  • 1
theRoot
  • 571
  • 10
  • 33
0
driver.findElement(By.id("ctl00_cphClaimFlow_tabcontainerClaimFlow_tabFulfillment_Shipping_rdoYesFindMyPhone")).click();
Leon Barkan
  • 2,676
  • 2
  • 19
  • 43