Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

Problem with WebDriverWait #2481

Closed
lukeis opened this issue Mar 3, 2016 · 4 comments
Closed

Problem with WebDriverWait #2481

lukeis opened this issue Mar 3, 2016 · 4 comments

Comments

@lukeis
Copy link
Member

lukeis commented Mar 3, 2016

Originally reported on Google Code with ID 2481

What steps will reproduce the problem?
1. Declaring a WebDriverWait


What is the expected output? What do you see instead?
The test has to open the webpage and wait till the element is found.


Selenium version:2.6
OS: Windows 7
Browser: Internet Explorer 
Brower version: 9

This is the code I have written


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;


import javax.swing.text.html.HTML;

public class sampleTest {
    WebDriver driver;
//    WebDriverWait wait = new WebDriverWait(driver, 120);

    @BeforeTest
    public void setUp() {
        driver = new InternetExplorerDriver();
    }

    @AfterTest
    public void tearDown() {
        driver.quit();
    }

    @Test
    public void TestToWait() {
        driver.get("www.google.co.in");
//        WebElement element = wait.until(new ExpectedCondition<WebElement>() {
//            public WebElement apply(WebDriver webDriver) {
//                return webDriver.findElement(By.name("q"));
//            }
//        });
//        element.click();
    }
}

The program above, works fine. When I uncomment the lines(which are commented) I get
the following error.

org.testng.TestNGException: 
Cannot instantiate class com.selenium.test.sampleTest
    at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:37)
    at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:372)
    at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:284)
    at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:109)
    at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:184)
    at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:120)
    at org.testng.TestRunner.initMethods(TestRunner.java:394)
    at org.testng.TestRunner.init(TestRunner.java:228)
    at org.testng.TestRunner.init(TestRunner.java:198)
    at org.testng.TestRunner.<init>(TestRunner.java:154)
    at org.testng.remote.RemoteTestNG$1.newTestRunner(RemoteTestNG.java:139)
    at org.testng.remote.RemoteTestNG$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG.java:272)
    at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:544)
    at org.testng.SuiteRunner.init(SuiteRunner.java:142)
    at org.testng.SuiteRunner.<init>(SuiteRunner.java:106)
    at org.testng.TestNG.createSuiteRunner(TestNG.java:1116)
    at org.testng.TestNG.createSuiteRunners(TestNG.java:1103)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:955)
    at org.testng.TestNG.run(TestNG.java:900)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:110)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:205)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:174)
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:106)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:28)
    ... 27 more
Caused by: java.lang.NullPointerException
    at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:187)
    at org.openqa.selenium.support.ui.FluentWait.<init>(FluentWait.java:93)
    at org.openqa.selenium.support.ui.WebDriverWait.<init>(WebDriverWait.java:57)
    at org.openqa.selenium.support.ui.WebDriverWait.<init>(WebDriverWait.java:36)
    at com.selenium.test.sampleTest.<init>(sampleTest.java:20)
    ... 32 more

Process finished with exit code 0

I really cannot figure out what the problem is and what has WebDriverWait goto do with
TestNG? 

Reported by amkhapare on 2011-09-17 06:41:32

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Put the line
WebDriverWait wait = new WebDriverWait(driver, 120);
into setUp method after driver initialization.

Reported by barancev on 2011-09-17 18:10:59

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Marking as closed.

Reported by simon.m.stewart on 2011-09-19 07:20:16

  • Status changed: WorkingAsIntended

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

haha, I have some related posts in my blog, you can read them for reference.

http://ksblog.org/index.php?q=WebDriverWait-ajax-javascript-asynchronized-refresh&id=31

http://ksblog.org/index.php?q=one-useful-class-for-webdriver-a-package-class-for-webdriverwait&id=39

Reported by yankaisheng on 2011-10-22 14:24:13

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Reported by luke.semerau on 2015-09-17 18:13:45

  • Labels added: Restrict-AddIssueComment-Commit

@lukeis lukeis closed this as completed Mar 3, 2016
@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant