Clicking on an element with xvfb

218 views
Skip to first unread message

phtrivier

unread,
Jun 8, 2012, 10:11:05 AM6/8/12
to Selenium Users
I'm running selenium 2 tests on a headless machine in the display
created by an xvfb server. Very often I get error because elements are
present in the page but not "visible" (although they're not hidden or
anything)

elem = self.driver.find_element_by_xpath(delete_token_xpath)
displayed = wait_until_true(lambda : elem.is_displayed())
if not displayed:
self.test.fail("Button to remove label (xpath %s) is still
not visible" % delete_token_xpath)

find_element_by_xpath will not complain, but the returned element is
not displayed (although it should be). Of course, the test works when
running on a machine with a real screen. I made sure that :

* the xvfb is running, with a big enough resolution
* my webdriver launches firefox, and I use the new 'maximize_window'
from selenium 2.21 to make sure the window is big enough

What can I look at to understand why my elements can not be clicked ?
What is the right setup of xvfb to run selenium tests ? Or an
alternative ?

Also, more generally, could someone explain why clicking is so hard to
implement in Se2 ? Almost right from the start we had to revert to
calling javascript to click on elements, since Se2 wasn't always able
to click on elements (usually for "visibility issues", although
elements were present and visible...) I suppose there is some browser
intricacies that makes it possible to find DOM elements with arbitrary
xpath, but not to click on those ...

Brian Goad

unread,
Jun 18, 2012, 1:09:55 PM6/18/12
to seleniu...@googlegroups.com
I have a similar setup using xvfb, but I have not had much issues with clicking on elements. I just have to ensure they are there and visible (so I implemented a waitForVisible(type, selector) method. My click wrapper method calls waitForVisible, and all is good.

Occasionally, I will come across issues with clicking on elements that appear when another element is hovered over. Sometimes the browser shows the elements, but the DOM doesn't register them as being visible. Thus, I had to write javascript injection that forces the elements to register as visible while being hovered over.

Hopefully, you are not running into one of these type of issues. I would recommend that in your teardown you take a screenshot if there is a failure so you can see what the browser's state was at that time to ensure the elements you are attempting to click are indeed visible.

Brian
Reply all
Reply to author
Forward
0 new messages