public class LaunchBrowser_TestNG {
@Test
public void LaunchBrowser() throws InterruptedException{
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "/projects/challenge/phantomjs-2.1.1-linux-x86_64/bin/phantomjs");
WebDriver driver = new PhantomJSDriver(caps);
System.out.println("PhantomJS Headless Driver launched");
// Write your script here
driver.get("https://google.com");
Thread.sleep(5000);
System.out.println ("Launch Browser is successful");
System.out.println("Page Title : " driver.getTitle());
//Searching for "Fresco Play" in Google search
driver.findElement(By.xpath("//input[@class='gLFyf gsfi']")).sendKeys("Fresco Play");
driver.findElement(By.xpath("//input[@class='gLFyf gsfi']")).sendKeys(Keys.ENTER);
Thread.sleep(5000);
System.out.println("Page Title : " driver.getTitle());
}
}
There is some error at By.xpath. It says -
the method xpath is undefined for the method BY.
CodePudding user response:
Possibly a required import is missing. You need to add:
import org.openqa.selenium.By;
CodePudding user response:
First, you need to import import org.openqa.selenium.By
on top of your test.
and then like:
driver.findElement(By.xpath,value= "//input[@class='gLFyf gsfi']")).sendKeys("Fresco Play");
Try this if the above code is not working:
driver.find_element(By.XPATH,"//input[@class='gLFyf gsfi']")