1

I am working on automation of a website using Selenium WebDriver and Java, but I am stuck in a situation where on a button click a new webpage dialog opens and on that web page dialog I have perform Operations like entering values / selecting from Dropdowns.

Problem is I am unable to switch to that webpage dialog and even F12 window not working on that webpage dialog. This website is only working on IE. Please help me.

    driver.findElement(By.id("buttonOK")).click(); //operation on main browser
    Thread.sleep(3000);
    driver.switchTo().activeElement();  // This didn't switch to webpage dialog

     for(String winHandle : driver.getWindowHandles()){  // this code also didn't switchTo webpage dialog
            driver.switchTo().window(winHandle);
        }

    driver.findElement(By.name("textDataValue")).sendKeys("test"); //operation on webpage dialog

Screenshot: enter image description here

1 Answer 1

1

I think that the current for loop code just switches between all open windows, but you want to switch to a particular open window.

I'd recommend that each loop iteration look for the first By.tagName("title") element and extract the title element's text. That should hopefully correspond to the text in the top bar of the window.
Then, for each window that you switch to, compare that fetched 'title' text with the text which you know is in the top bar of the dialog window ("Add/Modify Address -- Webpage Dialog"). If they match, then you can break out of the for loop and hopefully Selenium will be focused on that dialog window.

Sign up to request clarification or add additional context in comments.

Comments

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.