Trying to run chromedriver for Selenium results in errors - selenium-webdriver

I used this code:
public class ChromeTest {
#Test
public void LaunchChrome_Method2() {
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-infobars");
options.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com");
}
}
from this website:
http://www.automationtestinghub.com/selenium-chromedriver/

There are errors in your code. This can be fixed by the following:
Your filename is Chrom.java hence your public class name must be Chrom not ChromeTest.
Add import statements for WebDriver and #Test and ChromeDriver.
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

Related

Test annotation code is not working, just BeforeMethod is working

My code is working until #BeforeMethod and it is opening the URL, but what I'm typing after #Test is not working. It is not typing credentials on the login page, hence Test failed.
package com.test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
// import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class Great {
WebDriver driver;
#BeforeMethod
public void setup()
{
System.setProperty("webdriver.chrome.driver", "C:\\Program Files
(x86)\\Google\\Chrome\\Application\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String baseurl = "https://getfieldforce.com/dishqa";
driver.get(baseurl);
// Actions act = new Actions(driver);
}
#Test (priority=0)
public void login()
{
System.out.println("Login process starts");
driver.findElement(By.id("email")).sendKeys("123#p.com");
driver.findElement(By.id("password")).sendKeys("123456");
driver.findElement(By.id("cta")).click();
System.out.println("Login Sucessfully");
}
Removing webdriver from this line fixed the issue; WebDriver driver = new ChromeDriver();
Thanks for looking into this :-)

i am unable to type text in loginpage by using sendkeys

I am unable to type text in login page, tried all the solutions provided online but issue still exists. anyone help me to resolve the issue. below is the code:
package com.individual.newlearn;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class secondProgram {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "./driver/chromedriver.exe");
ChromeDriver driver = new ChromeDriver();
driver.get("https://www.google.co.in/webhp?ie=UTF-8&rct=j&gws_rd=cr&dcr=0&ei=9Wq2WozGFIH4vgSJ2LmoAw");
Thread.sleep(2000);
driver.findElement(By.xpath("//a[text()='Gmail']")).click();
//driver.navigate().to("https://accounts.google.com/signin/v2/identifier?hl=EN&flowName=GlifWebSignIn&flowEntry=ServiceLogin");
driver.findElement(By.xpath("//a[text()='Sign In']")).click();
Thread.sleep(2000);
driver.findElement(By.id("identifierId")).sendKeys("mail id");
java script i used for typing mail id:
/*WebElement searchbox = driver.findElement(By.id("identifierId"));
JavascriptExecutor myExecutor = ((JavascriptExecutor)driver);
myExecutor.executeScript("arguments[0].value='mail id';", searchbox);
Thread.sleep(3000);*/

How do I automate testing for hybrid apps which has it's web view resources from assets?

I am using Appium for testing my Android Hybrid App.
What parameter should I give for the RemoteWebDriver constructor? I tried giving the html file path from the internal storage, but it's not working.
Any help would be appreciated.
package firsttestngpackage;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class FirstTestNGFile {
WebDriver driver;
#BeforeClass
public void setup() throws MalformedURLException{
DesiredCapabilities capabilities=new DesiredCapabilities();
capabilities.setCapability("browserName", "Chrome");
capabilities.setCapability("platformVersion", "7.1.1");
capabilities.setCapability("deviceName", "MotoG5splus");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("automationName", "Appium");
capabilities.setCapability("app", "C:\\Users\\chandrahas\\Downloads");
driver=new RemoteWebDriver(new URL(""),capabilities);
capabilities.setCapability("appPackage", "com.reliance.agencydev");
}
#Test
public void testirm()throws Exception {
driver.findElement(By.xpath("//*[#id=\"userName\"]/input")).sendKeys("9642039085");
driver.findElement(By.xpath("//*[#id=\"password\"]/input")).sendKeys("password");;
}
}
Where is your Appium server running? If it's on your local machine, try with:
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub/"), capabilities);
Also try moving the line where you declare appPackage capability to before you create your driver.

Openbravo ERP application using selenium webdriver but not able to find any web element

When I'm trying to run this code, I am unable to find any web element
package PremisesManagement;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
public class openbravo {
#Test
public void openbravoLoginTest() throws InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver.exe");
WebDriver d = new ChromeDriver();
d.get("http://119.81.222.91:8080/camps/security/Login_FS.html");
Thread.sleep(3000);
d.findElement(By.id("user")).sendKeys("xyz");
WebDriverWait wait = new WebDriverWait(d, 120);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("//button[#id='buttonOK']")));
d.findElement(By.xpath("//button[#id='buttonOK']")).click();
}
}
Actually located elements are inside a frame with id paramFrame1, So you need to switch this frame before finding element as below :-
System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://119.81.222.91:8080/camps/security/Login_FS.html");
WebDriverWait wait = new WebDriverWait(driver, 10);
//First switch to frame with id paramFrame1
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("paramFrame1"));
//Now find the element
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("user"))).sendKeys("xyz");
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("buttonOK"))).click();

unable to launch internet explorer in TestNG

I am new in TestNG. This is my code which I tried in eclipse, but there is a problem occurring in launching internet explorer.
The error it is giving is
org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (WARNING: The server did not provide any stacktrace information)
This is the complete code....
package com.tcs.medmantra;
import java.io.File;
import java.io.IOException;
import java.util.Set;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class Registration {
WebDriver driver;
WebElement element;
WebElement element2;
WebDriverWait waiter;
#Test(priority = 1)
public void register_With_Cash() throws RowsExceededException, BiffException, WriteException, IOException
{
driver=new InternetExplorerDriver();
driver.get("https://172.25.155.250/loginpage.aspx");
//((JavascriptExecutor)driver).executeScript("window.resizeTo(1366, 768);");
waiter = new WebDriverWait (driver, 40);
driver.findElement(By.id("txtuname")).sendKeys("122337");
driver.findElement(By.name("txtpwd")).sendKeys("Tcs!#345");
driver.findElement(By.id("btnsubmit")).click();
sleep(25000);
//print URL
String url = driver.getCurrentUrl();
System.out.println(url);
}
#BeforeTest
public void beforeTest() {
File file = new File("D:\\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
}
#AfterTest
public void afterTest() {
driver.quit();
}
}
As the error says you need set the protected mode same for all zones, either enabled or disabled. Preferred would be enabled. See here
Change your code to include the path for InternetExplorerDriver.
File file = new File("C:/Selenium/iexploredriver.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();

Resources