Selenium remote webdriver doesn't accept desiredCapabilities - opera

I am trying to launch a operaDriver using remoteWebdriver, and my code is:
static private IWebDriver driver;
DesiredCapabilities capability = DesiredCapabilities.Opera();
driver = new RemoteWebDriver("http://localhost:9515", capability);
however this gives me error of RemoteDriver has invalid arguments, and it specifies RemoteDriver takes OpenQA.Selenium.ICapabilities type as argument, which is violated in my code.
I am confused here. Could anyone please share some lights?
Thank you very much!

I think you can try this
It is as in java. You can try a URL class in C#
grid_url = new URL("http://localhost:9515/wd/hub");
driver = new RemoteWebDriver(grid_url, capability);

Related

The method implicitlyWait(long, TimeUnit) from the type WebDriver.Timeouts is deprecated what is that Mean really?

[enter image description here][1]
please resolve issue , please update the same
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(());
driver.get("https://accounts.google.com/signin");
driver.manage().window().maximize();
You can use like this :
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("https://accounts.google.com/signin");
driver.manage().window().maximize();
If you are using selenium 4 try this:
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
driver.manage().timeouts().scriptTimeout(Duration.ofSeconds(30));
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(60));
Deprecated
It means the method implicitlyWait(long, TimeUnit) is no more supported and you should use an updated method to serve the same purpose.
You can change your code to
long time = 2000;
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(time));
Instead of arguments (long, TimeUnit), this method now takes arguments as Duration.ofSeconds(time)

When I execute selenium script, following it browser is being closed Automatically?

I am writing selenium script and It's working perfect but when code is running then my browser is automatically closed?
public static void main(String args[])
{
System.setProperty("webdriver.chrome.driver",
"./chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("URL");
String email = "EMAil";
String password = "123";
int ELEMENT_WAIT_TIME_SEC = 60;
WebDriverWait explicitWait = new WebDriverWait(driver, ELEMENT_WAIT_TIME_SEC);
String locator = "//input[#type='email'][#aria-label='Email']";
By findBy = By.xpath(locator);
WebElement Login = explicitWait.until(ExpectedConditions.elementToBeClickable(findBy));
Login.click();
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("arguments[0].setAttribute('aria-invalid',true);", Login);
Login.sendKeys(email);
String plocator = "//input[#type='password'][#aria-label='Password']";
By findByp = By.xpath(plocator);
WebElement Password = explicitWait.until(ExpectedConditions.elementToBeClickable(findByp));
Password.click();
jse.executeScript("arguments[0].setAttribute('aria-invalid',true);", Password);
Password.sendKeys(password);
}
Check your code. May be you used driver.close() method to close the browser.
Just comment or delete that code and the browser will not close automatically.
I got over this error by using the Code Runner extension of VS Code instead of manually running node file-path.
Works well.
This is a case of browser version compatibility issue with chrome. so update your chromedriver.exe in sync with current version of Chrome browser.

unable to create webdriver object reference

I am trying to create webdriver object reference in the class which is not having main method. it is not allowing me to create the object. Finally, I tried with an instance and it is not working(not identifying driver)
public class LoginPage
{
public static WebDriver driver;
static ResourceLoader loader = new ResourceLoader();
public static String loginVerify(String username, String password)
{
System.out.println("navigated to loginvarify() :: ");
logger.info("username is "+username);
logger.info("password is "+password);
try
{
driver.findElement(By.id(loader.getProperty(Constants.UserName))).sendKeys(username);
}
Please help me
public class LoginPage
{
System.setProperty("webdriver.chrome.driver", "src/main/resources/drivers/osx/chromedriver"); // path to your chrome driver
public static WebDriver driver = new ChromeDriver();
static ResourceLoader loader = new ResourceLoader();
public static String loginVerify(String username, String password)
{
System.out.println("navigated to loginvarify() :: ");
logger.info("username is "+username);
logger.info("password is "+password);
try
{
driver.findElement(By.id(loader.getProperty(Constants.UserName))).sendKeys(username);
}
I have updated your code, kindly refer you are missing your driver initialization. I have initialized to chromeDriver(), if you are using firefox initialize it accordingly.
System.setProperty("webdriver.chrome.driver",
"src/main/resources/drivers/osx/chromedriver"); // path to your chrome
driver
If you are not having the chrome driver, kindly download and place it in your directory path and pass the path reference accordingly.
https://sites.google.com/a/chromium.org/chromedriver/downloads
Let me know if you still face any issue or anything is not clear.
WebDrvier driver = new FireFoxDriver(); //driver initialization
driver.FindElement(By.Id(IdName)); //to find elements by ID in UI
You can define your chrome driver path using System.setProperty("webdriver.chrome.driver", "C:\Spring Workspace\chromedriver\chromedriver.exe"); // path to your chrome driver or you can define the path in the environment variable so you don't have to use this setProperty code again and again......if you are using firefox driver than not need to define any setProperty beacause it is already defined inside org.openqa.selenium.firefox.FirefoxDriver....

selenium RC ,WebDriver driver = new RemoteWebDriver(new URL(serverUrl), capability);

See this code:
String serverUrl = "http://127.0.0.1:4444/wd/hub";
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setJavascriptEnabled(true);
WebDriver driver = new RemoteWebDriver(new URL(serverUrl), capability);
When a request comes in, it will be create new instance, which will take between 2 and 4 seconds. For me, this is too long. How can I make it faster?
You are doing the right thing .You can increase number of nodes and browsers that will help in executing all of your tests in less time .

how would I run Selenium test through the GRID using C#

i have just set-up the selenium grid on my local machine and everything seems to be up and running.
my question is, is there a way I can run the test case from selenium grid node (command prompt)?
I am using WebDriver for creating my testcase using .Net
Sample code from here
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
// Requires reference to WebDriver.Support.dll
using OpenQA.Selenium.Support.UI;
class GoogleSuggest
{
static void Main(string[] args)
{
// Create a new instance of the Firefox driver.
// Notice that the remainder of the code relies on the interface,
// not the implementation.
// Further note that other drivers (InternetExplorerDriver,
// ChromeDriver, etc.) will require further configuration
// before this example will work. See the wiki pages for the
// individual drivers at http://code.google.com/p/selenium/wiki
// for further information.
WebDriver driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4444/wd/hub"),
DesiredCapabilities.FirefoxDriver());
//Notice navigation is slightly different than the Java version
//This is because 'get' is a keyword in C#
driver.Navigate().GoToUrl("http://www.google.com/");
// Find the text input element by its name
IWebElement query = driver.FindElement(By.Name("q"));
// Enter something to search for
query.SendKeys("Cheese");
// Now submit the form. WebDriver will find the form for us from the element
query.Submit();
// Google's search is rendered dynamically with JavaScript.
// Wait for the page to load, timeout after 10 seconds
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); });
// Should see: "Cheese - Google Search"
System.Console.WriteLine("Page title is: " + driver.Title);
//Close the browser
driver.Quit();
}
}
WebDriver driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4444/wd/hub"),
DesiredCapabilities.FirefoxDriver());
OR in c#
IWebDriver driver;
DesiredCapabilities capability = new DesiredCapabilities();
driver = new RemoteWebDriver(
new Uri("http://hub-cloud.com/wd/hub/"), capability);
driver.Navigate().GoToUrl("http://www.google.com");