Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use clickandwait in Selenium Webdriver using Java?

I am trying to click on the object, to show the list of value pop-up.

I used the following script, but unable to populate the list value pop-up.

Driver.findElement(By.xpath(OR.getProperty(Object))).click();
   Thread.sleep(1000L);

Is there any other way to click and wait for the object?

like image 805
user2943890 Avatar asked Nov 18 '13 09:11

user2943890


People also ask

What is called automatically when clickAndWait is used?

waitForPageToLoad. pauses execution until an expected new page loads. Called automatically. when clickAndWait is used.

How do I run a jar file in Selenium?

To do that, right-click the . java file and select Run As > Java Application. Click the image to enlarge it. This will run your Selenium script: start Firefox, navigate to the tested web page, perform the test actions, and then close the browser.


2 Answers

Driver.findElement(By.xpath(OR.getProperty(Object))).click();
WebDriverWait wait = new WebDriverWait(Driver, timeoutInSeconds);
wait.until(ExpectedConditions.elementToBeClickable(By.id("yourId"))); 

There are other conditions like visibilityOf so choose the one which suits you most - documentation here.

like image 63
Petr Mensik Avatar answered Oct 23 '22 03:10

Petr Mensik


            String mainWindowHandle = driver.getWindowHandle();
            System.out.println(mainWindowHandle);

           wait.until(ExpectedConditions.elementToBeClickable(By.xpath(OR.getProperty(Object)));
            Driver.findElement(By.xpath(OR.getProperty(Object))).click();

            PageUtil.sleep(3000);
            Set<String> s1 = driver.getWindowHandles();

            Iterator<String> ite = s1.iterator();
            while (ite.hasNext()) {
                String popupHandle = ite.next().toString();
                System.out.println(popupHandle + " Present Pop Up window name");
                if (!popupHandle.contains(mainWindowHandle)) {
                    driver.switchTo().window(popupHandle);
                }
            }


WebDriverWait wait = new WebDriverWait(Driver, timeoutInSeconds);
wait.until(ExpectedConditions.elementToBeClickable(By.id("yourId"))); 
Driver.findElement(By.id("yourId")).click();

driver.switchTo().window(mainWindowHandle);
like image 44
Satish Avatar answered Oct 23 '22 04:10

Satish