selenium - How to wait for an element which does not come always in a page using webdriver -


Can someone put some ideas on my query?

Question: In my application, a pop up that often comes, but for some time it is not so. I have to check whether pops up or not, and then take action on that. This pop up takes some time to appear in the page as well.

My solution: First of all, I waited for a pop-up with a clear wait condition. After that, if the pipe shows whether pop-up is displayed on the page or not. If performed, do the work, take other action.

Now, if there is no pop up, then I'm getting time out exception.

Here is my code:

  FluentWait & LT; WebDriver & gt; Wait_1 = New Fluent Weight & lt; WebDriver & gt; (Driver) .withTimeout (30, Time Unit, SEOCNDS). Polishing Every (5, Time Usenet. SEONSS). Inning (Knowledge Exception.Class). Inning (Timeout Exception.class); // Up Time Exception Received if pop-up is not available wait_1.until (ExpectedConditions.VisibilityOfElementLocated (By.id ("some id")); If (driver.findElement (By.id ("some id") isDisplayed ()) {System.out.println (driver.findElement (By.id ("some id")). GetText ()); // click on some elements;} {// 'enter code'}  

You can try something like

  int count = 0; {If (driver.getWindowHandles (). Size ()> 1) {string parentwandow = driver. GetWindowHandle (); Set up & lt; String & gt; Windowhands = driver.getwondhoundle (); Iterator & LT; String & gt; Iterator = windowhandle Knitter (); While (iterator.hasNext ()) {string handle = iterator.next (); If (Handle.contains (parentWindow)) {driver.switchTo () Window (handle); // Warning is currently something to do}} driver. SwitchTo () Window (parent); break; } Calculate ++; } While (calculated & lt; 100);  

It will wait until it becomes vigilant or counting up to 100. You can change the count value according to your needs.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -