1
votes

I have written below code to select the radio button and it was working fine but today its not working.Please find the code and corresponding error message

Code1:

WebDriverWait wait = new WebDriverWait(driver,10);
    WebElement radio = wait.until    (ExpectedConditions.presenceOfElementLocated(By.id("0_2485A_StartDate")));
    ((JavascriptExecutor)driver).executeScript("arguments[0].click()", radio);

Error1: 'Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for presence of element located by: By.id: 0_2485A_StartDate'

Code2:

 WebDriverWait wait = new WebDriverWait(driver,10);
        WebElement radio = wait.until    (ExpectedConditions.presenceOfElementLocated(By.id("Radio_0_2485A")));
        ((JavascriptExecutor)driver).executeScript("arguments[0].click()", radio);

Error2: 'Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for presence of element located by: By.id: Radio_0_2485A'

Code3:

WebDriverWait wait = new WebDriverWait(driver,10);
        WebElement radio = wait.until(ExpectedConditions.elementToBeClickable(By.id("0_2485A_StartDate")));
        radio.click();

Error3: 'Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for element to be clickable: By.id: 0_2485A_StartDate'

Code4:

WebDriverWait wait = new WebDriverWait(driver,10); WebElement radio = wait.until(ExpectedConditions.elementToBeClickable(By.id("Radio_0_2485A"))); radio.click();

Error4: 'Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for element to be clickable: By.id: Radio_0_2485A'

HTML:

    <th class="radio">
    <input id="0_2485A_StartDate" type="hidden" value="18/12/2015 00:01:00">

    <input name="Products[0].ProductCode" title="5 Year Fixed Rate Until 28/02/2021 with £999 Fee" id="Radio_0_2485A" type="radio" value="2485A">
    <label for="Radio_0_2485A">
       5 Year Fixed Rate Until 28/02/2021 with £999 Fee
  </label>
    </th>

Please do suggest.

2
No its not dynamically generated. - Lakshmi D

2 Answers

2
votes

presenceOfElementLocated just checking the element existing in the DOM, So if you are using this with ExpectedConditions your code would work fine.

But as I'm seeing, exception stacktrace states you're using elementToBeClickable, Actually elementToBeClickable is used to wait until element visible and clickable while located element is hidden and it would never be visible.

You're locating hidden element that's why you're in trouble.

You should try to locate actual radio element as below :-

WebDriverWait wait = new WebDriverWait(driver,10);
WebElement radio = wait.until(ExpectedConditions.elementToBeClickable(By.id("Radio_0_2485A")))
radio.click()
0
votes

I had no way to replicate your actual web browser scenario, but just tried to copy your html code and put in a simple html template. I saw that you tried almost everything.. if possible can you give the url where others can look into the page.

I tried like this:

driver.findElement(By.xpath("//input[@value='2485A']")).click();

and it worked. Let me know if this helps.