Currently Browsing

Posts Tagged ‘ Selenium Problem ’

How to check presence of an element when it disappears in less than 500ms

It can happen that the element you want to check only appears for a fraction of a second. This can produce false failures when the element appears in between the standard 500ms when WebDriver checks the wait condition. What you can do is to set up a FluentWait object with a specific polling time. It works almost the same as other kinds of wait functions in WebDriver.

The code is the following:



	Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
				.withTimeout(20, java.util.concurrent.TimeUnit.SECONDS)
				.pollingEvery(200, java.util.concurrent.TimeUnit.MILLISECONDS)
				.ignoring(NoSuchElementException.class);
		
		Function<WebDriver, WebElement> function = new Function<WebDriver, WebElement>() {
			
			@Override
			public WebElement apply(WebDriver driver) {
				return driver.findElement(exportSnackbarCss);
			}		
		};
		
		wait.until(function);

Solution for – Could not start Selenium Session : Connection timed out

If you get the “Could not start Selenium Session : Connection timed out” while running a test scenario it is usually due to the ports not matching for the Server and the client and results in “Selenium server not able to make a connection with the local client machine”.

a sample error message:

 java.lang.RuntimeException: Could not start Selenium session: Connection timed out: connect
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:89)
at com.ibm.lconn.files.test.ui.BaseFilesSeleniumTestCase.setUp(BaseFilesSeleni umTestCase.java:54)
at junit.framework.TestCase.runBare(TestCase.java:128)
at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:21 2)
at junit.framework.TestResult$1.protect(TestResult.java:106) 

The solution for it is to make sure to run the on the same ports. The default port where the selenium server starts up is 4444.

Solution for Selenium IDE – Your browser doesnt support Xml Http Request

If you get the “Your browser doesnt support Xml Http Request” error while running tests
in Selenium IDE even if its shows that all tests passed below is the cure for it:

This issue only happens on versions of Selenium IDE prior to 1.0.6

So there are two workarounds to this problem:

1) Get the newest version and use that (currently 1.0.7) :

http://seleniumhq.org/download/

2) Or if for whatever reason you are stuck with the version you have here is a workaround:

http://code.google.com/p/selenium/issues/detail?id=388

 

Solution for Selenium already running on port problem

When running selenium server often it happens that it can’t start with the following error:

“Selenium is already running on port 4444. Or some other service is.”

This happens because Selenium uses the 4444 port as its default and if you already started selenium or some other application is using that port Selenium will be prevented from using the same port.

There are several ways around this problem:

  • Find the application that is blocking/using the 4444 port and turn it off or change its port. Using the command “netstat -ano” (under Linux use “netstat –tcp –listening –programs”)¬†from command prompt identify the applications PID and then look it up in task manager. If you don’t see the PID in task manager make sure to turn the column on in View->Select Columns:
    Once you have identified the application either kill it or change its port. Now its safe to run “java -jar selenium-server.jar” and Selenium will start up correctly.
  • Change the port Selenium is using. Run “java -jar selenium-server.jar -port XXXX” where XXXX is the desired unused port for example “java -jar selenium-server.jar -port 4448”.
    This fix is also useful if you want several instances of the selenium server running on the same machine.