How to fix chromedriver error in console tab? - selenium

I have run my test script but I got this error message in the console tab:
"Starting ChromeDriver 84.0.4147.30 (48b3e868b4cc0aa7e8149519690b6f6949e110a8-refs/branch-heads/4147#{#310}) on port 30846
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Aug 22, 2020 5:41:42 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C"
Below is my java code:
package seleniumProjectTutorial;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class SeleniumWebDriver {
WebDriver driver;
public void invokeBrowser() {
try {
System.setProperty("webdriver.chrome.driver","D:\\Selenium\\Drivers\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.get("https://www.google.com");
driver.close();
driver.quit();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
SeleniumWebDriver myobject = new SeleniumWebDriver();
myobject.invokeBrowser();
}
}
Is there a need for me to fix it and how? Thank you.

If you wanted to stop this warning message in the console you need to pass --silent argument to chromedriver to stop console message. you can achieve this using 'withSilent(true)' method
Launch chromedriver using chromedriverservice as shown in below sample code
ChromeDriverService cdservice=new ChromeDriverService.Builder().usingDriverExecutable(new File("/path/to/chromedriver.exe"))
.withLogFile(new File("/path/to/chromedriver.log"))
.withSilent(true)
.usingAnyFreePort()
.build();
WebDriver driver = new ChromeDriver(cdservice);
driver.get("http://www.google.com");

Related

Getting "Timed out receiving message from renderer" while running selenium script

I am using Chrome v81 and ChromeDriver vChromeDriver 81.0.4044.20. My selenium script is running successfully and able to identify web elements also. But i am using one loop there, which is not working-
public static void main(String[] args) throws InterruptedException {
String projectPath = System.getProperty("user.dir");
System.setProperty("webdriver.chrome.driver", projectPath + "\\Drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://rahulshettyacademy.com/AutomationPractice/");
Thread.sleep(3000);
WebElement cb = driver.findElement(By.xpath("//input[#value='option1']"));
cb.click();
Thread.sleep(2000);
if (cb.isSelected())
cb.click();
Thread.sleep(3000);
List<WebElement> allCBs = driver.findElements(By.xpath("//input[#value='checkbox']"));
for (int i = 0; i < allCBs.size(); i++) {
System.out.println(i);
}
driver.close();
}
Output-
INFO: Detected dialect: W3C
[1588922113.669][SEVERE]: Timed out receiving message from renderer: 0.100
[1588922113.771][SEVERE]: Timed out receiving message from renderer: 0.100
Change your xpath with this:
//*[#id='checkbox-example']/child::*/descendant::input

Unable to find the element on emulator screen of Android app

The element appears within the appium view but unfortunately the element does not seems visible while automating it.
private AndroidDriver driver;
String idOfCNIC = "com.tez.androidapp:id/imageViewNICDetails";
this.driver.findElement(By.id(idOfCNIC))`
Following is the driver initialization code :
private static AndroidDriver driver;
public static AndroidDriver getDriver() {
if (driver == null) {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "920121cb3c7fc34a");
caps.setCapability("platformName", "Android");
caps.setCapability(CapabilityType.VERSION, "6.0.1");
caps.setCapability(CapabilityType.BROWSER_NAME, "Android");
caps.setCapability("app", "path_of_app");
(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
try {
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), caps);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
return driver;
}
Hi could you please use following versions of Appium java client and Selenium:
Appium Java-Client : 6.0.0-BETA5
Selenium-server : 3.9.1 Appium
Desktop as Appium Inspector : 1.6.1
Also please try with the following code for driver initialization :
private static AndroidDriver<?> driver;
public static AndroidDriver getDriver() {
if (driver == null) {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "920121cb3c7fc34a");
caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
caps.setCapability(MobileCapabilityType.AUTOMATION_NAME,"Appium ");
caps.setCapability(MobileCapabilityType.VERSION, "6.0.1");
caps.setCapability(MobileCapabilityType.APP, "path_of_app");
caps.setCapability("appWaitActivity", "*");
try {
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), caps);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
return driver;
}
I hope this solves your problem. Thanks!

Selenium Ebay Script

I have logged into Ebay and want to click the hyperlink of 'My collections' which is under "G'day [username]". The issue is now I can not find the element of 'My collections'. The error message is "Unable to locate element: (//li[#id='gh-ucol']/a)
Please refer to the below steps how I replicate:
Open Ebay via Firefox
Click Log in hyperlink
Enter the user name password then click log in button
Click "G'day [username]"
Select 'My Collection' from the droplist
This is my Selenium Java Script:
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class KevinTest {
public static void main(String[] args) throws InterruptedException{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.ebay.com.au");
driver.manage().window().maximize();
Thread.sleep(20);
driver.findElement(By.linkText("Sign in")).click();
Thread.sleep(100);
driver.findElement(By.xpath("(//input[#placeholder='Email or username'])[2]")).sendKeys("my#username");
driver.findElement(By.xpath("(//input[#placeholder='Password'])[1]")).sendKeys("mypassword");
driver.findElement(By.id("sgnBt")).click();
boolean tf;
try {
driver.findElement(By.id("errf")).getText();
tf = true;
}catch(NoSuchElementException e) {
tf = false;
}
if (tf == true) {
System.out.println("Incorrect Password");
driver.close();
}else {
System.out.println("Log in successfully");
}
driver.findElement(By.id("gh-eb-u")).click();
Thread.sleep(100);
driver.findElement(By.xpath("(//*[#id='gh-ucol']/a)")).click();
}}
Its a good practice to use implicit wait after initiating the driver.
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Use the below id for the 'Click "G'day [username]'.
driver.findElement(By.id("gh-ug")).click();
Use the below xpath for collection.
driver.findElement(By.id("//*[#id="gh-ucol"]/a")).click();
Since we have used implicit wait you can remove all other thread.sleeps. Hope this helps. Thanks.

UnReachableBrowserException in Chome with Selenium Webdriver

i am getting UnhandledBrowserException when trying the below code in chrome:
public class myClass {
public static void main(String[] args) {
// declaration and instantiation of objects/variables
System.setProperty("webdriver.chrome.driver", "C://Program Files (x86)//Google//Chrome//Application//chrome.exe");
WebDriver driver= new ChromeDriver();
String baseURL = "http://newtours.demoaut.com";
String expectedTitle = "Welcome: Mercury Tours";
String actualTitle = "";
// launch Firefox and direct it to the Base URL
driver.get(baseURL);
// get the actual value of the title
actualTitle = driver.getTitle();
/*
* compare the actual title of the page witht the expected one and print
* the result as "Passed" or "Failed"
*/
if (actualTitle.contentEquals(expectedTitle)){
System.out.println("Test Passed!");
} else {
System.out.println("Test Failed");
}
//close Firefox
driver.close();
// exit the program explicitly
System.exit(0);
}
It is launching a new session in chrome but then throwing the exception. Any help would be highly appreciated.
I think you are hitting program executable instead of driver.
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver driver = new ChromeDriver();
It should be path to chrome driver not the chrome browser executable.
You can take a look at https://sites.google.com/a/chromium.org/chromedriver/getting-started

Grid concept in Selenium [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have written coding for browser opening with grid concept. I wrote the following code. I need to know its correct or wrong.
properties
----------
HUB=localhost
PORT=4444
Browser = chrome
Url=http://demo.guru99.com/v4/index.php
Code
----
package processor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import org.openqa.selenium.Platform;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class Browser {
public static void main(String[] args) throws FileNotFoundException, IOException {
RemoteWebDriver driver;
Properties prop;
prop = new Properties();
prop.load(new FileInputStream("./config.properties"));
String hub = prop.getProperty("HUB");
String port = prop.getProperty("PORT");
String browser = prop.getProperty("Browser");
String url = prop.getProperty("Url");
if (browser.equalsIgnoreCase("chrome") || browser.equalsIgnoreCase("ie")
|| browser.equalsIgnoreCase("firefox")) {
if (browser.equalsIgnoreCase("chrome")) {
try {
DesiredCapabilities dc;
dc = new DesiredCapabilities();
dc.setBrowserName(browser);
dc.setPlatform(Platform.WINDOWS);
System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe");
driver = new ChromeDriver();
System.out.println("Chrome Browser is Initialising..........");
driver.manage().window().maximize();
driver.get(url);
} catch (Exception e) {
System.out.println("Problem Occurred while Initialising Chrome Browser. Check for the Driver Name & Path !!!!!!!!!!");
}
}
if (browser.equalsIgnoreCase("ie")) {
try {
DesiredCapabilities dc;
dc = new DesiredCapabilities();
dc.setBrowserName(browser);
dc.setPlatform(Platform.WINDOWS);
System.setProperty("webdriver.ie.driver", "./Drivers/IEDriverServer.exe");
driver = new InternetExplorerDriver();
System.out.println("Internet Explorer is Initialising..........");
driver.manage().window().maximize();
driver.get(url);
} catch (Exception e) {
System.out.println("Problem Occurred while Initialising Internet Explorer. Check for the Driver Name & Path !!!!!!!!!!");
}
}
if (browser.equalsIgnoreCase("firefox")) {
try {
DesiredCapabilities dc;
dc = new DesiredCapabilities();
dc.setBrowserName(browser);
dc.setPlatform(Platform.WINDOWS);
driver = new FirefoxDriver();
System.out.println("Firefox is Initialising..........");
driver.manage().window().maximize();
driver.get(url);
} catch (Exception e) {
System.out.println("Problem Occurred while Initialising Firefox. Check for the Driver Name & Path !!!!!!!!!!");
}
}
}
else {
System.out.println("Invalid Browser. Check Browser Name in Properties File.......... ");
}
}
}
Kindly see the code and tell me the correct code. Grid Concept i need to apply.
To use selenium with the grid you need to start a Remote webdriver. What you're doing here is starting a local webdriver of types:
driver = new ChromeDriver();
driver = new InternetExplorerDriver();
driver = new FirefoxDriver();
This is not how you request a browser from the grid.
Furthermore, the path to the driver (System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe");) must be supplied to the grid, so you cannot set this in your code here.
You do this as follows:
java -jar selenium-server-standalone-2.53.0.jar -role hub -Dwebdrivers.chrome.driver=chromedriver.exe
What you are currently doing is creating local webdrivers, you are not connecting to the grid at all. Connecting to the grid is done as follows:
driver = new RemoteWebDriver(hub, dc);