Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hover over on element and wait with Selenium WebDriver using Java

EDIT: So I figured out a simple way to hover over the element, but I want to wait for a result to pop up. The Chrome webdriver hovers over the element and moves on too fast for me to be able to see text. How can I get it to stay hovered until the text pops up? I looked at Wait() and until(), but I can't seem to get them to work properly (I assume that's because I'm not really waiting for a boolean to be true in the code. Unless someone has some suggestions?). Here's what I have thus far...

WebDriver driver = getWebDriver();
By by = By.xpath("//*[@pageid='" + menuItem + "']");
Actions action = new Actions(driver);
WebElement elem = driver.findElement(by);
action.moveToElement(elem);
action.perform();

Thanks again everyone!

Cheers.

like image 428
dr4g1116 Avatar asked Apr 30 '13 17:04

dr4g1116


1 Answers

You can't rely on sleeps so you should try this:

WebElement myDynamicElement = (new WebDriverWait(driver, 10))
  .until(ExpectedConditions.presenceOfElementLocated(By.id("myDynamicElement")));

You have a plenty of methods in the ExpectedConditions class.

Here is some info:

  • http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp

  • http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html

Hope you find this useful.

like image 119
Carlos Avatar answered Oct 23 '22 15:10

Carlos