My test cases are successfully executing through the terminal and Maven in my local environment but when I run the tests in a Jenkins job, they fail due to the browser size. (I have taken a screenshot and from the screenshot I determined that browser size was small.)

(One thing I am not clear on is - Is the browser size dependent on the system screen size?)

My test tries to select a value from drop down but due to end of the page Selenium fails to select the value from drop down. The test passes locally, as the page is rendered so that the drop down is on screen and does not need to be scrolled to.

Screenshot of running test showing parts of the page must be scrolled to reach them.

If any one is aware about this issue please share your views and experience.

  • I don't understand the browser size thing. Test cases for Selenium should not fail due to size of browser, unless you are specifically adding that. Please attach the screenshot of the failure for better understanding. Nov 3, 2015 at 6:08
  • The screenshot is of a browser from local machine or server? Nov 3, 2015 at 7:06
  • @log_file: it is from server
    – QAMember
    Nov 3, 2015 at 7:15
  • I see two drop down options. Which option are you selecting? Nov 3, 2015 at 8:10
  • I am selecting from quantity dropdown
    – QAMember
    Nov 3, 2015 at 9:48

1 Answer 1


Setting the browser size in selenium is limited by the resolution of the display (Xvfb or similar on a build server).

So for example if your browser size is set as below, it can only fill the maximum of the display.

Dimension expectedWindowSize = new Dimension(1288, 988);

Basically it behaves the same as if you have a browser physically on your screen. If you increase the build server's resolution, you will find it works.

This can be done using something similar to;

Xvfb :0 -ac -screen 0 1024x768x24 &

An easier solution is if you scroll down the page within Selenium to find the element you want before interacting with it. You can do that with something like the below;

his will scroll until the element is in view :

WebElement element = driver.findElement(By.id("id_of_dropdown"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
//click on dropdown and so on
  • Hello @Adurbe, Thanks for your valuable answer.Right now I am doing the 2nd approach (scrolling in to view the element).But calling scroll method every time before interacting the element is not such a good practice.So that I am looking for an alternative way.
    – QAMember
    Nov 3, 2015 at 11:29
  • As you said ,I will use Dimension class and update you the answer. Anyway Thank you very much for your answer
    – QAMember
    Nov 3, 2015 at 11:31
  • I have add how to set the Xvfb on the server, gives another option to follow. Good luck!
    – ECiurleo
    Nov 3, 2015 at 11:37
  • Where should I place this "Xvfb :0 -ac -screen 0 1024x768x24 &"
    – QAMember
    Nov 3, 2015 at 11:39
  • you would run it on the (linux) server your jenkins is running against x.org/archive/X11R7.6/doc/man/man1/Xvfb.1.xhtml It basically sets the framebuffer on the system which is its "display size"
    – ECiurleo
    Nov 3, 2015 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.