Selenium remote WebDriver issue - selenium

I am trying to do parallel execution using Selenium in my machine. I have configured hub and node successfully. But in my code, I am getting an error at remote web driver initialization.
My code:
package com.selenium.gautham;
import org.openqa.selenium.Platform;
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.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;
public class test {
#Test
public static void sample()
{
DesiredCapabilities cap =DesiredCapabilities.internetExplorer();
cap.setBrowserName("ie");
cap.setPlatform(Platform.WINDOWS);
RemoteWebDriver driver =RemoteWebDriver(new URL("http://localhost:4444/wb/hub"),cap);
driver.get(url);
}}
I'm getting this error:
The constructor RemoteWebDriver(URL, DesiredCapabilities) is undefined
Where did I do wrong?
Screenshot of Code

In your imports (before the start of the class), i haven't seen an import for the URL Class. I believe you are trying to use the below constructor of RemoteWebDriver Class.
RemoteWebDriver(java.net.URL remoteAddress, Capabilities desiredCapabilities)
If so, i would suggest you to first try replacing the below line
RemoteWebDriver driver =RemoteWebDriver(new URL("http://localhost:4444/wb/hub"),cap);
to the one below and see if its working fine.
RemoteWebDriver driver = RemoteWebDriver(java.net.URL("http://localhost:4444/wb/hub"), cap);
If you see the above alternative working then import
java.net.URL

Related

Unable to run selenium webdriver scripts even after all the jars installed

I am unable to run selenium webdriver scripts on pc. I have all the necessary jar files and java installed on my pc but still I am getting just too many errors.I have attached the build path and errors in links below.
Here is the code:-
package Webdriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class firstscript {
public static void main(String args[]) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\gkuma218\\Downloads");
WebDriver driver=new ChromeDriver();
String baseurl="https://stage-portal.uhcglobal.com/testMyUHC/generate-open-token.html";
driver.get(baseurl);
driver.findElement(By.id("txteeid")).sendKeys("00000907777");
driver.findElement(By.id("txtdob")).sendKeys("19920828");
driver.findElement(By.id("txtfirstname")).sendKeys("Sanette");
driver.findElement(By.id("txtlastname")).sendKeys("ABATE");
driver.findElement(By.id("txtgroupid")).sendKeys("0742631");
driver.findElement(By.id("btnSubmit")).click();
}
}
Here are the errors:-
https://i.stack.imgur.com/m2euR.png
Here is the build path:-
https://i.stack.imgur.com/l5692.png
Possibly a classic case of Cyclic redundancy.
Solution:
Either you rename the project name as seleniumTests and module name as webdriverTests
Or you may like to create a new project with a unique name excluding the keywords selenium and webdriver.

Unable to take screenshot of CEF application using Selenium

I am using Selenium to automate the CEF application. I am successfully able to perform operations like click etc. But not able to take the screenshot using Selenium driver. As it is very much required feature for automation. How can I do this?
I'm using the following:
CEF application - sample application provided by CEF
selenium jar - selenium-server-standalone-3.0.1
cef_binary_3.2924.1564.g0ba0378_windows64_client
chromedriver
Find the below code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.OutputType;
public class Example {
public static void main(String[] args) {
// Path to the ChromeDriver executable.
System.setProperty("webdriver.chrome.driver", "D:/CEFTesting/chromedriver.exe");
// Path to the CEF executable.
ChromeOptions options = new ChromeOptions();
options.setBinary("D:/CEFTesting/cef_binary_3.2924.1564.g0ba0378_windows64_client/Release/cefclient.exe");
WebDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com/xhtml");
sleep(3000); // Let the user actually see something!
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("ChromeDriver");
searchBox.submit();
sleep(5000); // Let the user actually see something!
String screenshotBase64 = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64);
System.out.println(screenshotBase64);
sleep(5000); // Let the user actually see something!
driver.quit();
}
}
I am facing the error.
I'm using the following:
CEF application - Sample application provided by CEF (link - https://bitbucket.org/chromiumembedded/cef/wiki/UsingChromeDriver.md)
selenium jar - selenium-server-standalone-3.0.1
cef_binary_3.2924.1564.g0ba0378_windows64_client
chromedriver
Here is the code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.OutputType;
public class Example {
public static void main(String[] args) {
// Path to the ChromeDriver executable.
System.setProperty("webdriver.chrome.driver", "D:/CEFTesting/chromedriver.exe");
// Path to the CEF executable.
ChromeOptions options = new ChromeOptions();
options.setBinary("D:/CEFTesting/cef_binary_3.2924.1564.g0ba0378_windows64_client/Release/cefclient.exe");
WebDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com/xhtml");
sleep(3000); // Let the user actually see something!
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("ChromeDriver");
searchBox.submit();
sleep(5000); // Let the user actually see something!
String screenshotBase64 = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64);
System.out.println(screenshotBase64);
sleep(5000); // Let the user actually see something!
driver.quit();
}
}

i am not able to launch the web browser using TestNG

below is the code : im not able launch the browser using the code . please suggest the solution
import org.openqa.selenium.Test;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.Assert;
import org.testng.annotations.*;
public class NewTest {
public WebDriver driver;`enter code here`
#Test
public void VerifyHomepageTitle() {
WebDriver driver = new FirefoxDriver();
driver.navigate().to("http://google.com");
driver.quit();
}
}
You are closing the web page immediately after opening using 'driver.quit()'. Comment this code and try you will see the difference.

Can't access sub menu using webdriver

Can't access submenu eventhough i was able to hover over the parent menu and this is happening only for the site:
upon login need to access Candidates under Recruitment
http://www.livetech.co.in/hrms/symfony/web/index.php/auth/login
code:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.Alert;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import static org.testng.Assert.assertTrue;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.testng.annotations.*;
public class Mouseover {
public static void main(String[] args) throws Exception
{
WebDriver driver= new FirefoxDriver();
driver.navigate().to("http://www.livetech.co.in/hrms/symfony/web/index.php /auth/login");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.name("txtUsername")).sendKeys("selenium");
driver.findElement(By.name("txtPassword")).sendKeys("selenium");
driver.findElement(By.name("Submit")).click();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
Actions action=new Actions(driver);
action.moveToElement(driver.findElement(By.xpath("//a[#id='menu_recruitment_viewRecruitmentModule']/b"))).click();
//driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Thread.sleep(10000);
driver.findElement(By.xpath("//div[#id='wrapper']/div[2]/ul/li[5]/ul/li/a")).click();
System.out.println("executed");
}
}
can anyone help.
Regards,
Ram.
First of all you are using incorrect Xpath. Remove . . In your case it should start from //. //*[#id='menu_recruitment_viewRecruitmentModule']/b
Secondly if your motive is to reach to Candidates tab then directly click on Recruitment. It will solve your purpose.
Finally if you want to use mouse hover then you can easily implement it, but I suggest not to do it because you have easy way to do it.
Last call is always your
Thanks

Need help on Desiredcapabilities class

Hi I am learning selenium grid for the first time.I am unable to understand why Desired capabilities class is used to set browser name and platform details in a remote machine.
please let me know if there is any proper documentation on it apart from google-wiki page
Thanks
prathima
Not all remote machines (or sessions) support the features requested by a user. E.g. user may want to use Chrome on Windows but some machines are only running Firefox on Linux.
The desiredCapabilities is used to describe the features of a session requested by user. You can refer to this link and this link for more info.
- when user send request to remote machine to run a particular test on
a particular browser on a particular platform.
- It doesn't mean that all the remote machine will support all the
features requested by user such as (Particular browser on a
particular machine).
**Example:**
- If user request to execute a testcase on internet explorer on Linux
platform. It doesn't mean that always Linux machine has internet
explorer it would have firefox not internet Explorer(Because it is
open source).
- Linux machine doesn't support the features requested by a User. so
that, that point of time we will use DesiredCapabilites class to set
the platform , Browser Name and version of browser of Remote Machine
to execute the Test.
Example:
package grid;
import static org.junit.Assert.*;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class SimpleGridTest
{
WebDriver driver;
String baseUrl , nodeUrl;
#Before
public void setUp() throws Exception
{
WebDriver driver;
String baseUrl , nodeUrl;
baseUrl = "https://www.facebook.com";
nodeUrl = "http://192.168.10.21:5568/wd/hub";
DesiredCapabilities capability = DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
capability.setPlatform(Platform.WIN8_1);
driver = new RemoteWebDriver(new URL(nodeUrl),capability);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(2, TimeUnit.MINUTES);
}
#Test
public void test() throws InterruptedException
{
driver.manage().window().maximize();
driver.get("https://www.google.co.in");
driver.findElement(By.linkText("Gmail")).click();
driver.findElement(By.id("Email")).sendKeys("abc#gmail.com");
driver.findElement(By.id("Passwd")).sendKeys("1234");
driver.findElement(By.id("signIn")).click();
}
#After
public void tearDown() throws Exception
{
driver.quit();
}
}