Here are the details of my Development Environment:
-Visual Studio 2012 Ultimate with Update 4
-Google Chrome Version 40.0.2214.94 m
-Windows 7 Professional with 32-bit Operating System
My Google Chrome browser's User Agent String is:
Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36
The C# code in my Automated UI test code is as follows:
var options = new PhantomJSOptions();
// Chrome User Agent ( Chrome Version 40.0.2214.94 m )
options.AddAdditionalCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36");
driver = new OpenQA.Selenium.PhantomJS.PhantomJSDriver(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\..\packages\PhantomJS.1.9.8\tools\phantomjs"), options);
url = new Uri("http://localhost:2816/");
IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(90.00));
wait.Until(ExpectedConditions.ElementIsClickable( By.XPath("//a[text()='Users']")));
IWebElement btn = waitArg.Until<IWebElement>((d) => {
try{
return d.FindElement( By.XPath("//a[text()='Users']") );
}
catch {
return null;
}
});
btn.Click();
Unfortunately the above code is having a tough time finding the elements. I believe that if I could configure the PhantomJS driver used in my code to more closely emulate my Google Chrome Version 40.0.2214.94 m browser that is on my desktop then the Automated UI test code should be able to give more consistent and accurate testing results whenever the tests are run.
Could someone please suggest if I could make some modifications to the following code that will more closely emulate my Google Chrome Version 40.0.2214.94 m browser?
var options = new PhantomJSOptions();
// Chrome User Agent ( Chrome Version 40.0.2214.94 m )
options.AddAdditionalCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36");
driver = new OpenQA.Selenium.PhantomJS.PhantomJSDriver(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\..\packages\PhantomJS.1.9.8\tools\phantomjs"), options);
Update With Answer with help of @artjom-b
var options = new PhantomJSOptions();
options.AddAdditionalCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36");
var service = PhantomJSDriverService.CreateDefaultService(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\..\packages\PhantomJS.1.9.8\tools\phantomjs"));
service.SslProtocol = "any";
driver = new PhantomJSDriver(service, options);
url = new Uri("http://localhost:2816/");
// 1280, height: 1024
// @artjom-b strongly recommened that the Driver's Window Size be quite large. Let's set the Window Size to quite large.
driver.Manage().Window.Size = new System.Drawing.Size(1280, 1024); // Size is a type in assembly "System.Drawing"