-1

this is my code

    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.google.com");
    WebElement searchBox = driver.findElement(By.name("q"));
    searchBox.sendKeys("Packt Publishing");
    searchBox.submit();

these are my imports:

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

(i don't know why here it puts them in the same line)

What it does is that it opens a new firefox page with an empty tab ... what's wrong? I looked for other people in this site with the same problem and I did not find an answer.

cherry
  • 39
  • 1
  • 1
  • 3

1 Answers1

0

While you work with Selenium 3.4.0 and geckodriver v0.17.0 and Mozilla Firefox 53.0, you have to download and save geckodriver in your system and provide the absolute path of the geckodriver in your code. You can consider to use the following code block to initiate Google Search by calling submit() method:

    System.setProperty("webdriver.gecko.driver", "C:\\your_directory\\geckodriver.exe");
    WebDriver driver = new FirefoxDriver();
    driver.get("https://google.com");
    driver.findElement(By.name("q")).clear();
    driver.findElement(By.name("q")).sendKeys("Packt Publishing");
    // CASE C : Submitting the Search String through submit()
    driver.findElement(By.xpath("//input[@value='Google Search']")).submit();

Let me know if this Answers your Question.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I don't think so even if I put only this code WebDriver driver = new FirefoxDriver(); driver.get("http://www.google.com"); it does not work – cherry Jul 08 '17 at 12:58
  • Change `driver.get("google.com");` to `driver.get("https://google.com");`. Thanks – undetected Selenium Jul 08 '17 at 13:08
  • I'm sorry it does not work. I did everything you told me . – cherry Jul 08 '17 at 13:33
  • and anyways this code driver.get("google.com"); was an example I did not write exaclty that,. – cherry Jul 08 '17 at 13:35
  • See this discussion thread [Why Firefox requires GeckoDriver](https://stackoverflow.com/questions/43660195/why-firefox-requires-geckodriver/43661697#43661697). If the error still persists, copy your exact code and error stack trace along with Selenium-Gecko-Mozilla versions. Thanks – undetected Selenium Jul 08 '17 at 13:39