Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

isElementPresent in selenium 2.0

Hello all I am using webdriver so if I want to use selenium;s rc function isElementPresent I have to emulate selenium rc so I do something like this:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class new {
 private static void one_sec() {
  Thread.sleep(4000);
 }
 public static void main(String[] args) {    
  WebDriver driver = new FirefoxDriver();
  driver.get(something1);
  Selenium selenium = new WebDriverBackedSelenium(driver, something1); 
  selenium.click("//html...");
  one_sec();
  System.out.println(selenium.isElementPresent("text"));
  WebDriver driverInstance = ((WebDriverBackedSelenium) selenium).getWrappedDriver();
  ...
  }

and I always get false as result of isElementPresent and of course element "text" is on the web (which is using GWT).

like image 338
user729076 Avatar asked May 07 '11 17:05

user729076


People also ask

What is IsElementPresent Selenium?

IsElementPresent Method. Verifies that the specified element is somewhere on the page.

How does Selenium define implicit wait?

Implicit Wait directs the Selenium WebDriver to wait for a certain measure of time before throwing an exception. Once this time is set, WebDriver will wait for the element before the exception occurs. Once the command is in place, Implicit Wait stays in place for the entire duration for which the browser is open.


1 Answers

I really like Rostislav Matl's alternative Moving to Selenium 2 on WebDriver, Part No.1:

driver.findElements(By.className("someclass")).size() > 0;

Javadoc: org.openqa.selenium.WebDriver.findElements(org.openqa.selenium.By by)

like image 93
Alberto Avatar answered Sep 24 '22 21:09

Alberto