我正面临着PhantomJS reg定位这些问题的一些问题。我已经完成了之前已回答的问题,其中给出了两种可能的解决方案:
我已尝试过两种解决方案,但我的代码仍无效。 代码:
public class Headless_phantomJS {
@Test
public void googlesearch() throws InterruptedException
{
File path=new File("C:/Third party softwares/phantomJS/phantomjs-2.1.1-windows/phantomjs-2.1.1-windows/bin/phantomjs.exe");
System.setProperty("phantomjs.binary.path",path.getAbsolutePath());
WebDriver driver= new PhantomJSDriver();
driver.manage().window().maximize();
driver.navigate().to("https://www.google.co.in/");
System.out.println("inside Test");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.xpath("//input[@id='lst-ib']")).isEnabled();
driver.findElement(By.xpath("//input[@id='lst-ib']")).sendKeys("lol");
driver.findElement(By.xpath(".//*[@id='tsf']/div[2]/div[3]/center/input[1]")).click();
}
}
答案 0 :(得分:1)
这是您自己的代码块,它可以与PhantomJS 2.1.1一起执行,并进行一些调整,并为您提供一些Sysouts:
@Test
public void googlesearch()
{
File path=new File("C:\\Utility\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
System.setProperty("phantomjs.binary.path",path.getAbsolutePath());
WebDriver driver= new PhantomJSDriver();
driver.manage().window().maximize();
driver.navigate().to("https://www.google.co.in/");
System.out.println("inside Test");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
System.out.println("Checking if the Search field is Enabled");
driver.findElement(By.name("q")).isEnabled();
System.out.println("Sending lol to Search field");
driver.findElement(By.name("q")).sendKeys("lol");
System.out.println("Clicking on Google Search button Next");
driver.findElement(By.name("btnG")).click();
System.out.println("Google Search Completed");
}