I click on button which downloads PDF file from server and opens it in new tab. After click i wait when the tab will be opened:
TimeSpan timeSpan = TimeSpan.FromSeconds(10);
WebDriverWait waiter = new WebDriverWait(driver, timeSpan);
waiter.Until(drv => drv.WindowHandles.Count == 2);
When this PDF file is opened i switch to new tab:
string handle = drv.WindowHandles.Last();
drv.SwitchTo().Window(handle);
Then i try to access Url property on web driver:
TimeSpan timeSpan = TimeSpan.FromSeconds(10);
WebDriverWait waiter = new WebDriverWait(driver, timeSpan);
waiter.Until(driver => driver.Url.StartsWith("blob:"));
But i get this error:
The HTTP request to the remote WebDriver server for URL http://localhost:44829/session/fc28864b05b7a2b3ad16fd69e29fb48d/url timed out after 60 seconds.
This issue appears only in Headless mode on linux machine:
public static IWebDriver Create()
{
ChromeOptions options = new ChromeOptions();
options.AddArgument("headless");
options.AddArgument("no-sandbox");
options.AddArgument("window-size=1920x1080");
IWebDriver driver = new ChromeDriver(options);
return driver;
}
But there are no problems in simple chrome mode on Windows:
public static IWebDriver Create()
{
IWebDriver driver = new ChromeDriver();
driver.Manage().Window.Maximize();
return driver;
}
This issue appears when trying to search elements too.
Related
I try to launch Selenium web driver using Chrome but get such error:
Cannot start the driver service on http://localhost:45189
Here is my code:
public string FunctionHandler(string input, ILambdaContext context)
{
var driver = CreateLambdaChromeDriver();
driver.Url = "https://www.wikipedia.org";
var html = driver.PageSource;
return html;
}
public ChromeDriver CreateLambdaChromeDriver()
{
ChromeOptions options = new ChromeOptions();
// Set the location of the chrome binary from the resources folder
// Include these settings to allow Chrome to run in Lambda
options.AddArguments("disable-gpu");
options.AddArguments("headless");
options.AddArguments("window-size=1366,768");
options.AddArguments("no-sandbox");
return new ChromeDriver(options);
}
How can I fix this error?
I am using the ChromeDriver in an nunit test to test whether a complex page loads:
public ChromeDriver Driver { get; private set; }
[OneTimeSetUp]
public void Setup()
{
ChromeOptions co = new ChromeOptions{};
co.AddArgument("no-sandbox");
Driver = new ChromeDriver( co) ;
Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(120);
Driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(120);
Driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(120);
Driver.Manage().Window.Maximize();
}
As you can see I have tried to increase timeouts to 2 miutes everywhere yet when I run
Driver.Navigate().GoToUrl(url);
against the page I get
OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL timed out after 60 seconds.
The page does take longer than 60 seconds to load, So how do I increase the 60 seconds ?
You need to increase the DefaultCommandTimeout in RemoteWebDriver. You can do it by using the ChromeDriver(ChromeDriverService, ChromeOptions, TimeSpan) or ChromeDriver(string, ChromeOptions, TimeSpan) overloads
ChromeOptions co = new ChromeOptions{};
Driver = new ChromeDriver("path to ChromeDriver.exe", co, TimeSpan.FromSeconds(120));
// or
Driver = new ChromeDriver(ChromeDriverService.CreateDefaultService(), co, TimeSpan.FromSeconds(120));
I have the following code. I update the selenium web driver to v3.14 and it shows the obsolete and error messages.
DesiredCapabilities capabilities; --deprecated
capabilities = DesiredCapabilities.Chrome(); --has the error for Selennium wen driver v3.14
capabilities.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Windows));
Uri uri = new Uri(hub url);
_driver = new RemoteWebDriver(uri, capabilities, TimeSpan.FromSeconds(120));
From class RemoteWebDriver in OpenQA.Selenium.Remote, it still has the ICapabilities parameter
public RemoteWebDriver(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan commandTimeout);
I saw some posts using Chrome options. But I still cannot make it work for selenium grid. Any idea?
The following should work without incident:
ChromeOptions options = new ChromeOptions();
options.PlatformName = "windows";
Uri uri = new Uri(hub url);
_driver = new RemoteWebDriver(uri, options.ToCapabilities(), TimeSpan.FromSeconds(120));
Trying to use the webdriver to do some automated testing with crm. Im having issues with consistency. Ill run a test and it'll pass and the next time it will fail.I tried using waits and am still having this isuse. Has anyone used crm and selenium together and know any ideas on how to fix this issue?
IWebDriver driver = new FirefoxDriver();
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
// Thread.Sleep(10000);
driver.Navigate().GoToUrl("https://login.microsoftonline.com/ea791863-b17d-43ec-90ba-148d3fa0a86f/wsfed?wa=wsignin1.0&wtrealm=https%3a%2f%2fmerlintest.crm.dynamics.com%2f&wctx=pr%3dwsfederation%26rm%3dhttps%253a%252f%252fmerlintest.crm.dynamics.com%252f%26ry%3dhttps%253a%252f%252fmerlintest.crm.dynamics.com%252fmain.aspx&wct=2017-07-05T20%3a42%3a50Z&wreply=https%3a%2f%2fcloudredirector.crm.dynamics.com%3a443%2fG%2fAuthRedirect%2fIndex.aspx%3fRedirectTo%3dhttps%253a%252f%252fmerlintest.crm.dynamics.com%252fmain.aspx#386670653");
IWebElement emailOrPhone = driver.FindElement(By.Id("cred_userid_inputtext")); //email or phone input
IWebElement password = driver.FindElement(By.Id("cred_password_inputtext"));//password input
emailOrPhone.SendKeys("email");
password.SendKeys("password");
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("cred_sign_in_button")));
IWebElement enterButton = driver.FindElement(By.Id("cred_sign_in_button"));
enterButton.SendKeys(Keys.Enter);//login
driver.SwitchTo().DefaultContent();//switches frames ,needed this so we can grab elements
Thread.Sleep(5000);
//navigate to search box and enter candidate name
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementExists((By.ClassName("navImageFlipHorizontal"))));
driver.FindElement(By.ClassName("navImageFlipHorizontal")).Click();
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
Thread.Sleep(5000);
driver.FindElement(By.Id("navTabButtonSearchD365Id")).SendKeys("");
driver.FindElement(By.Id("findCriteriaImg")).Click();
WebDriverWait iwait = new WebDriverWait(driver, TimeSpan.FromSeconds(25));
IWebElement element = iwait.Until(
ExpectedConditions.ElementIsVisible(By.Id("searchTextBox")));
Thread.Sleep(5000);
driver.FindElement(By.Id("searchTextBox")).Clear();
driver.FindElement(By.Id("searchTextBox")).SendKeys("lisa steinburg");
driver.FindElement(By.Id("searchTextBox")).SendKeys(Keys.Enter);
I just want to test locally. With Internet Explorer it works. With Firefox, I get a timeout on line driver.FindElement :
var capabilitiesInternet = new OpenQA.Selenium.Remote.DesiredCapabilities();
capabilitiesInternet.SetCapability("ignoreProtectedModeSettings", true);
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl(url);
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement category = wait.Until<IWebElement>((d) =>
{
return d.FindElement(By.Name("login"));
});
// Login
driver.FindElement(By.Name("login")).SendKeys("test");
Error message is httpRequest to remotedriver timeout.
Upate: I think it's due to the fact that I have a portable version of Firefox 21 and an older version of FF which cannot work with Selenium whereas Selenium launch old version. So I tried to indicate the path of portable :
var capabilitiesInternet = new OpenQA.Selenium.Remote.DesiredCapabilities();
capabilitiesInternet.SetCapability("ignoreProtectedModeSettings", true);
string path = #"C:\Portable";
FirefoxProfile ffprofile = new FirefoxProfile(path);
IWebDriver driver = new FirefoxDriver(ffprofile);
Unfortunately it keeps running the old version (I cannot change the old version because of corporate environment).
Is there anyway to make this profile work ?
Not sure if it is your problem, but in order to 'point' Selenium to where Firefox is located, you are looking for the FirefoxBinary class:
var binary = new FirefoxBinary("pathtofirefox");
string path = #"C:\Portable";
FirefoxProfile ffprofile = new FirefoxProfile(path);
var driver = new FirefoxDriver(binary, profile);