2

Trying to set a Default language in my program. But after much googling i dident find any answers.

How can i input standard english accept language? is there any document i can read for all functions i can use in c# with PhantomJS? I dident find anything more then playing in Visualstudio controlls.

var driverService = PhantomJSDriverService.CreateDefaultService();

driverService.HideCommandPromptWindow = true;

driverService.LoadImages = false;
driverService.SslProtocol = "tlsv1";
driverService.IgnoreSslErrors = true;
driverService.ProxyType = "http";
driverService.Proxy = "";

using (var driver = new PhantomJSDriver(driverService))
{
    driver.Manage().Window.Size = new Size(1920, 1080); // Size is a type in assembly "System.Drawing"
    driver.Manage().Cookies.DeleteAllCookies();

    driver.Url = "https://www.thewebsite.com";

    Thread.Sleep(5000); // 5sec

    try
    {
        driver.FindElement(By.Name("email")).SendKeys("MyEmail");
        driver.FindElement(By.Name("fullName")).SendKeys("MyName");
        driver.FindElement(By.Name("username")).SendKeys("MyUsername");
        driver.FindElement(By.Name("password")).SendKeys("MyPassword");

        driver.TakeScreenshot().SaveAsFile("LetsSnapascreenshot.png", ImageFormat.Png);

    }
    catch (OpenQA.Selenium.NoSuchElementException exception)
    {
        var exmsg = exception;
        driver.TakeScreenshot().SaveAsFile("Snaperrorscreenshot.png", ImageFormat.Png);
    }
}
Chase
  • 934
  • 6
  • 18
Oscar vs
  • 376
  • 2
  • 4
  • 17

2 Answers2

1

I found the solution for this if anyone else is looking for it.

PhantomJSOptions options = new PhantomJSOptions();

options.AddAdditionalCapability("phantomjs.page.customHeaders.Accept-Language", "en,en;q=0.5");
IWebDriver driver = new PhantomJSDriver(options);

And now it outputs the accept-Language correct

Oscar vs
  • 376
  • 2
  • 4
  • 17
0

you can try to add a header

PhantomJSOptions options = new PhantomJSOptions();
options.AddAdditionalCapability("Accept-Language","en-DE,en;q=0.5"); 
IWebDriver driver = new PhantomJSDriver(options);

or write in your index.html as described in this answer

<script>
   localStorage.lang = 'en';
</script>
Community
  • 1
  • 1
pedrommuller
  • 15,741
  • 10
  • 76
  • 126
  • options.AddAdditionalCapability("Accept-Language", "en-DE,en;q=0.5"); Does not seems to work. I did try to set useragent with options and it worked. I also ready somewhere about a version bug but i should have the latest PhantomJS installed. – Oscar vs Jan 27 '16 at 00:23
  • I cant seems to find "index.html" where should this file be? – Oscar vs Jan 27 '16 at 01:14
  • you should change en-DE,en;q=0.5 to the language you want to set – pedrommuller Jan 27 '16 at 20:34
  • Thanks, but i did already solve it i still dont understand where the index.html file is. But i did mange to solve it with my answer below. You where on right track with AddAdditionalCapability. Thanks so much! – Oscar vs Jan 27 '16 at 20:39