-1

I've read all prior posts and tried all suggestions. I've verified the page is loading via taking a screenshot. It's there. I have a 30 second implicit wait in place, which PhantomJS waits for. I have a fully qualified URL. And i've tested the same simple code snippet below with ChromeDriver and it works by flipping to that driver. Any ideas?

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {
        var d = new PhantomJSDriver();
        //var d = new ChromeDriver();

        try
        {
            var s = "abc";
            d.Manage().Window.Maximize();

            d.Manage().Timeouts().ImplicitlyWait(System.TimeSpan.FromSeconds(10));
            d.Navigate().GoToUrl("http://www.google.com");

            var e = d.FindElement(By.Name("q"));
            e.SendKeys(s);
            e.Submit();

            Assert.AreEqual<String>(s + " - Google Search", d.Title);

        }
        catch(Exception e)
        {
            ((ITakesScreenshot)d).GetScreenshot().SaveAsFile("c:\\exception.png", System.Drawing.Imaging.ImageFormat.Png);
            Console.WriteLine(d.PageSource);
            throw e;
        }
        finally
        {
            d.Quit();
        }
    }

PhantomJS Output Window

Captain Kirk
  • 350
  • 6
  • 24

1 Answers1

0

Google may response with different HTML code depending on user agent and/or viewport size. Set a viewport of a desktop browser (like 1280x1024) to get a desktop version, whereas default PhantomJS viewport of 400x300 gets a lighter mobile version.

On how to change viewport size, see https://stackoverflow.com/a/23840494/2715393

Community
  • 1
  • 1
Vaviloff
  • 16,282
  • 6
  • 48
  • 56
  • Thanks for the advice Vaviloff. It was indeed an issue with Google serving up different HTML based on user agent. The By.id("") that I was using comes up missing in Phantom. I've updated the code to show that i'm using By.name("q") now which seems more resilient cross platform. I also added code to dump the page source on exception which revealed the issue. – Captain Kirk Oct 30 '16 at 23:59
  • Very nice! Logging everything and making screenshots makes PJS debugging easier. – Vaviloff Oct 31 '16 at 03:57