I just started learning Selenium.
This is my code:
package sele;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Abc {
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.close();
}
}
This is the exception:
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
at org.openqa.selenium.firefox.FirefoxDriver.createCommandExecutor(FirefoxDriver.java:277)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:247)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:242)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:238)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:127)
at sele.Abc.main(Abc.java:10)
I am not sure if it is the same in java but in C# you use:
driver.Quit();
at the end of your code. Some use
driver.Dispose();
This will work as well.
Look here for more Help.
Related
.clear() in my test script is not working with testng version 6.14.2 but when i am running the same code without testng the clear method is working as expected.
i am running the code as mentioned below:
driver.findElement(By.id("email")).clear();
But this loc is not performing any action.
Blockquote
clear() is working for me. refer the following snippet
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class Testngexample {
private WebDriver driver;
#BeforeClass
public void setUp() {
System.setProperty("webdriver.chrome.driver","Add chromedriver path chromedriver.exe");
driver = new ChromeDriver();
}
#AfterClass
public void tearDown() {
driver.quit();
}
#Test
public void GoogleEarch() throws InterruptedException {
driver.get("https://www.google.com/");
driver.manage().window().maximize();
driver.findElement(By.name("q")).click();
driver.findElement(By.name("q")).sendKeys("testing");
Thread.sleep(5000);
driver.findElement(By.name("q")).clear();
Thread.sleep(5000);
driver.close();
}
}
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Login {
public static void main(String[] args) {
WebDriver driver=new FirefoxDriver();
driver.get("https://www.mail.google.com");
driver.findElement(By.id("Email")).sendKeys("abc#gmail.com");
driver.findElement(By.id("Passwd")).sendKeys("xyz");
driver.findElement(By.id("signIn")).click();
}
}
I am trying to write a program to login automatically into gmail.
I have tried everything
please help!!!!
This is giving me the error like this:
Exception in thread "main" java.lang.NoSuchMethodError:com.google.common.
base.Platform.precomputeCharMatcher
(Lcom/google/common/base/CharMatcher;)
Lcom/google/common/base/CharMatcher;
at com.google.common.base.CharMatcher.precomputed(CharMatcher.java:664)
at com.google.common.base.CharMatcher.(CharMatcher.java:71)
at com.google.common.base.Splitter.on(Splitter.java:127)
at org.openqa.selenium.remote.http.JsonHttpCommandCodec.
(JsonHttpCommandCodec.java:59)
at org.openqa.selenium.remote.HttpCommandExecutor.
(HttpCommandExecutor.java:85)
at org.openqa.selenium.remote.HttpCommandExecutor.
(HttpCommandExecutor.java:70)
at org.openqa.selenium.remote.HttpCommandExecutor.
(HttpCommandExecutor.java:58)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.
start(NewProfileExtensionConnection.java:87)
at org.openqa.selenium.firefox.FirefoxDriver.startClient
(FirefoxDriver.java:271)
at org.openqa.selenium.remote.RemoteWebDriver.
(RemoteWebDriver.java:119)
at org.openqa.selenium.firefox.FirefoxDriver.
(FirefoxDriver.java:218)
at org.openqa.selenium.firefox.FirefoxDriver.
(FirefoxDriver.java:211)
at org.openqa.selenium.firefox.FirefoxDriver.
(FirefoxDriver.java:207)
at org.openqa.selenium.firefox.FirefoxDriver.
(FirefoxDriver.java:120)
at com.st.Login.main(Login.java:17)
First of all: that URL doesn't go anywhere (at least in my side). You can achieve what you want as follows:
driver.get("https://accounts.google.com/")
driver.findElement(By.id("Email")).sendKeys("");
driver.findElement(By.id("next")).click();
driver.findElement(By.id("Passwd")).sendKeys("");
driver.findElement(By.id("signIn")).click();
I am working on a project on regression testing using Selenium webdriver in java. I have written the following code to take a screenshot.
package SelTest;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
public class takeScreenShottest {
public WebDriver driver;
#Test
public void openBrowser() throws Exception{
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://www.google.com");
try{
driver.findElement(By.id("testing")).sendKeys("test");
}catch(Exception e){
System.out.print("I am in Exception");
getscreenshot();
}
}
public void getscreenshot() throws Exception{
File scrFile=((TakesScreenshot)).driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("E:\\Android-workspace\\Test1\\src\\ScreenShot\\screenshot.png"));
}
public static void main(String[] args) throws Exception{
takeScreenShottest ts = new takeScreenShottest();
ts.openBrowser();
}
}
I am getting an error for
File scrFile=((TakesScreenshot)).driver).getScreenshotAs(OutputType.FILE);
Why is this happening?
You can use this as below:
FileUtils.copyFile(((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE), new File("E:\\Android-workspace\\Test1\\src\\ScreenShot\\screenshot.png"));
Error solved. The error was TakesScreenshot cannot be resolved to a variable and Syntax error on token ")". So, I removed the ")." So the correct syntax was
File srcFile=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
When I run the code, I get the following error:
Cannot instantiate class mypackage.GoogleSearch
How can it be fixed?
Code:
package mypackage;
import org.testng.annotations.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class GoogleSearch {
public String url = "http://www.google.com/";
public WebDriver driver = new FirefoxDriver();
#Test
public void search() {
driver.get(url);
}
}
I got it working, apparently I needed to install the stand-alone server: https://code.google.com/p/selenium/downloads/detail?name=selenium-server-standalone-2.39.0.jar&can=1&q= If anyone could explain why it'd be great, with Visual Studio I just had to install selenium client
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();
}
}
Did you try adding a Thread.sleep to see if it is a timing problem?