0

I have written a simple script of selenium web driver in java to select and click on a Radio button , but I am unable to select and click on the second radio button 'ONE WAY FLIGHT' on web page: http://www.lot.com/pl/en

Here is my code:

WebDriver driver = new FirefoxDriver();
String web = "http://www.lot.com/pl/en";
driver.get(web);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
WebElement element;

element = driver.findElement(By.id("select2-departureAirport-container"));
element.click();
element.sendKeys("WAW");
element.sendKeys(Keys.ENTER);

/* RADIO BUTTON ERROR */
element = driver.findElement(By.cssSelector("input[value='SINGLE']"));
elementRadio.click();

And this is the error:

Exception in thread "main" org.openqa.selenium.ElementNotInteractableException:

And this is the fragment of HTML on the web page http://www.lot.com/pl/en:

<div class="b-row">
                <div class="b-column twelve">
                    <fieldset class="flight-type" role="radiogroup" aria-required="true">
                        <legend class="acc-hide">Choose flight type</legend>
                        <label class="booker-label radio-label">
                            <input data-f-focus="radio" id="ticketTypeReturn" type="radio" name="ticketType" class="required" value="RETURN" checked="checked" />

                            <span class="ci" aria-hidden="true"></span>
                            <span class="ci-label">Round-trip flight</span>
                        </label>
                        <label class="booker-label radio-label g-no-margin">

                            <input data-f-focus="radio" type="radio" name="ticketType" class="required" value="SINGLE" />
                            <span class="ci cis" aria-hidden="true"></span>
                            <span class="ci-label">One-way flight</span>
                        </label>
                        <p id="ticketTypeReturn--required" class="b-v-error" role="alert">Choose flight type</p>
                    </fieldset>

                </div>
            </div>

I am unable to understand why it is throwing exception.

0

2 Answers 2

2

Use below code :-

WebDriver driver = new FirefoxDriver();
String web = "http://www.lot.com/pl/en";
driver.get(web);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
WebElement element;

element = driver.findElement(By.id("select2-departureAirport-container"));
element.click();
element.sendKeys("WAW");
element.sendKeys(Keys.ENTER);

/* RADIO BUTTON ERROR */
element = driver.findElement(By.cssSelector("input[value='SINGLE']"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
Sign up to request clarification or add additional context in comments.

2 Comments

But i dont understand why my code dont work fine and I need a javascriptexecutor
some elements needs focus, waits(fluent or explicit waits) to perform action on it. I have used JavascriptExecutor because it is working directly on JS. You can try to provide some focus, waits if you don't want to use JavascriptExecutor
0

Did you try with xpath?

elementRadio = driver.findElement(By.xpath("//*[@id="flightBookingForm"]/div[2]/div[1]/div/fieldset/label[2]/span[2]"));
elementRadio.click();

2 Comments

the same error Exception in thread "main" org.openqa.selenium.ElementNotInteractableException
@mvillegas - I just updated my answer. Try now and lets see if it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.