0

I am trying to run my script in background using HtmlUnitDriver but it throwing Nosuchelementexection every time,but it getting the current url.

    import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class Example{
public static void main(String[] args) {
WebDriver driver = new HtmlUnitDriver(true); 
driver.get("http://www.google.com"); 
String url=driver.getCurrentUrl();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
System.out.println(url);
String Text=driver.findElement(By.id("gbqfba")).getText();
System.out.println(Text);
driver.findElement(By.xpath("//*[@id='gbqfba']")).getSize().getHeight();          
driver.findElement(By.xpath("//*[@id='gbqfba']")).getSize().getWidth();  
driver.findElement(By.xpath("//*[@id='gbqfba']")).click();
driver.quit();

} }

Raghu
  • 93
  • 2
  • 4
  • 11

1 Answers1

0

Did you try adding a Thread.sleep to see if it is a timing problem?

elcharrua
  • 1,582
  • 6
  • 30
  • 50