I'm not been able to import a class file from selenium 3.7.1 , although I have this class in the refrence library(which I have configured in the build path)
Please assist.
Below is a snapshot of my IDE where I'm trying to do the run the code
package mrLogin;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions; //Getting exception in this line
public class Login {
public static String driverPath = "C:/auto/Mass_Retail_Auto/bin/mrLogin/";
public static WebDriver driver;
public static ChromeOptions options;
public static void main(String[] args) {
try{
//options.AddExtension("C:/auto/Mass_Retail_Auto/bin/mrLogin/modheader
2.1.2.crx");
System.out.println("launching chrome browser");
System.setProperty("webdriver.chrome.driver",
driverPath+"chromedriver.exe");
driver = new ChromeDriver();
driver.navigate().to("http://google.com");
}
catch(Exception e ){
e.printStackTrace();
}
finally {
driver.close();
System.out.println("Browser closed!!!");
}
}
}
Use Selenium 3.0 or till 3.4 version which is the most stable one. You won't be facing any problem with those versions. My suggestion would be go for 3.0 version.
Related
package Purpose;
//import org.openqa.selenium.WebDriver;
import org.openqa.selenium.*;
//import javax.swing.plaf.basic.BasicInternalFrameTitlePane.SystemMenuBar;
public class program {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "F://ChromeDriver//chromedriver_win32 (3)//chromedriver.exe");
System.out.println("Hello");
WebDriver driver = new ChromeDriver();
driver.get("https://www.quora.com/");
}
}
it seems that only the path to the driver can be an issue.
choose on of the following methods:
place the driver in the same directory as the java file you are trying to run.
add chromedriver.exe to PATH environment variable (see how here)
and then use setProperty like the below:
System.setProperty("webdriver.chrome.driver", "chromedriver.exe")
I'm not getting title of the page,i tried in firefox as well as in chrome.
This is my package
package begin;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Title {
WebDriver driver;
public void tite()
{
driver=new FirefoxDriver();
System.setProperty("webdriver.firefox.driver","C:/selenium-java-3.0.0-beta3/Latest selenium/geckodriver.exe");
driver.get("http://newtours.demoaut.com/");
String titleofthepage=driver.getTitle();
System.out.println(titleofthepage);
}
public static void main(String[] args)
{
Title obj1=new Title();
obj1.tite();
}
}
Need to add wait attributes to driver element.
After creating driver add implicit wait
System.setProperty("webdriver.firefox.driver","geckodriverpath");
driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
You are finding page title immediately after launching web page. Here it will wait 30 secs before finding any element to web page.
Set the property before driver initialization So your code should be :
package begin;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Title {
WebDriver driver;
public void tite()
{
System.setProperty("webdriver.firefox.driver","C:/selenium-java-3.0.0-beta3/Latest selenium/geckodriver.exe");
driver=new FirefoxDriver();
driver.get("http://newtours.demoaut.com/");
String titleofthepage=driver.getTitle();
System.out.println(titleofthepage);
}
public static void main(String[] args)
{
Title obj1=new Title();
obj1.tite();
}
}
Selenium - The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files
I am new to selenium, could any one please help on this?
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.ie.driver",System.getProperty("user.dir")+ "\\iedriver\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("https://accounts.google.com/ServiceLogin?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1#identifier");
WebElement username = driver.findElement(By.id("Email"));
username.sendKeys("selenium");
}
Selenium - 3.3.1
Java - 1.8
Eclispe - Indigo
Compiler - 1.7
Use this code with Chrome Driver/Browser:
package demo;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class TestAnyURLMain {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.google.co.in/");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[#id='gbw']/div/div/div[1]/div[1]/a")).click();
driver.findElement(By.id("Email")).sendKeys("ABC");
}
}
Let me know if it helps you.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class CheckoutFlow {
public static void main(String[] args) {
// TODO Auto-generated method s
System.setProperty("webdriver.gecko.driver", "D:\\geckodriver.exe");
WebDriver driver= new FirefoxDriver();
driver.get("http://google.com");
}
}
While launching the URL - from Java code below error is coming
"Server not Found"
Your code is perfectly fine. This might be the issue with Firefox version,
firefox version(I'm using) 52.0.1.
If still it is not working then try to switch to chrome instead of firefox.
Chrome Code :
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class CheckoutFlow {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://google.com");
driver.manage().window().maximize();
driver.quit();
}
}
Now i modified the code but still i am getting Null Pointer Exception
Below is my modified code
enter code here
package lib;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeMethod;
//#SuppressWarnings("unused")
public class Login {
WebDriver driver;
#BeforeMethod
void Initalisation()
{
System.setProperty("webdriver.ie.driver", "C:\\Eclipse\\IEDriverServer.exe");
DesiredCapabilities capability=new DesiredCapabilities();
capability.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
InternetExplorerDriver driver=new InternetExplorerDriver(capability);
driver.get("http://segotn11540.rds.volvo.com/vss_connect_testr1/Login/Login.aspx");
}
public Login(String UserName,String BrandName)
{
driver.findElement(By.xpath("//input[#name='UserNameInputText']")).sendKeys(UserName);
driver.findElement(By.xpath("//input[#name='Brand']")).sendKeys(BrandName);
driver.findElement(By.xpath("//input[#name='CmdLogin']")).click();
String Title=driver.getTitle();
if(!Title.contains("VSS 4.0"))
{
System.out.println(UserName+""+"does not exists");
driver.quit();
}
CheckForCancel();
}
private void CheckForCancel() {
if(!driver.findElements(By.id("Cancel")).isEmpty())
{
driver.findElement(By.id("Cancel")).click();
}
}
}
Now I will create the main Java file
Blockquote
This will initalise the login with the parameters supplied
Import Login library
public class MessageBoard {
public static void main(String[] args)
{
Login login=new Login("TYP40FI","Volvo");
}
}
What is wrong in above code
Try to initialize the driver variable as
WebDriver driver = new WebDriver();
public Login(String UserName,String BrandName)
{
//Add this line in your code as you are trying in IE
driver = new InternetExplorerDriver();
driver.findElement(By.xpath("//input[#name='UserNameInputText']")).sendKeys(UserName);
driver.findElement(By.xpath("//input[#name='Brand']")).sendKeys(BrandName);
driver.findElement(By.xpath("//input[#name='CmdLogin']")).click();
String Title=driver.getTitle();
if(!Title.contains("VSS 4.0"))
{
System.out.println(UserName+""+"does not exists");
driver.quit();
}
CheckForCancel();
}
Debug and check: Is Initalisation() being called in the beginning?
Usually #BeforeMethod is called before test starts, so where is your #Test function. (syntax could be wrong)
If you don't really care about #Test property, that means your Main function needs to call Initalisation() before calling Login(...), otherwise the driver is not set yet (aka Null)