Phantom JS 无法找到元素(即使在给出隐式等待 aslo 之后)
Phantom JS is unable to find element (even after giving implicit wait aslo)
我在 PhantomJS reg 定位网络元素时遇到了一些问题。我已经完成了之前回答的问题,其中给出了 2 种可能的解决方案:
- 同步问题-给予隐式等待
- Css 选择器在 phantomjs 中不起作用。
我已经尝试了两种解决方案,但我的代码仍然无法正常工作。
代码:
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();
}
}
这是您自己的代码块,它在 PhantomJS 2.1.1 上运行良好,并进行了一些调整,并为您的方便添加了一些系统输出:
@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");
}
我在 PhantomJS reg 定位网络元素时遇到了一些问题。我已经完成了之前回答的问题,其中给出了 2 种可能的解决方案:
- 同步问题-给予隐式等待
- Css 选择器在 phantomjs 中不起作用。
我已经尝试了两种解决方案,但我的代码仍然无法正常工作。 代码:
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();
}
}
这是您自己的代码块,它在 PhantomJS 2.1.1 上运行良好,并进行了一些调整,并为您的方便添加了一些系统输出:
@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");
}