tags:

views:

88

answers:

2

I am searching for an element on a webpage by using its xpath. The xpath is correct and can find the element ONLY if I manually perform a click anywhere on the page first. If I do not do this before the statement runs it will not find the element.

I have tried many different attempts to allow focus on the page:

selenium.selectWindow(null);
selenium.fireEvent(xpath, "focus");
selenium.click(element on page);
selenium.mouseDown();
selenium.mouseUp();

After performing these functions the statement will still not find the element, but if I manually maximize the page and click anywhere on the page, then run the statement, the element is found. Can anyone help me out with this?

The statement I am using to find the element is:

selenium.isElementPresent("//div[@class='sample_class']");

Thanks!

+3  A: 

Instead of using XPath, try using the CSS selector for that item.

Use selenium.isElementPresent("css=div.sample_class"); as your selector. Saucelabs have explained it quite well at http://saucelabs.com/blog/index.php/2009/10/selenium-tip-of-the-week-start-improving-your-locators/

AutomatedTester
Thanks for the response. I am having the same issue using CSS selectors too. I can find the element only after a manual click is performed on the page. Without clicking on the page and executing the isElementPresent() method, it will return false. Is there a way to make the element available without having to perform any manual steps?
can you show the markup of the page so we have a look and make suggestions from there
AutomatedTester
A: 

moved

SeleniumUser
This should be a separate question really as they look subtly different
AutomatedTester