0

I am trying to get the URL of the second page of a yellowpages result with the following code:

var driverService = PhantomJSDriverService.CreateDefaultService();
var driver = new PhantomJSDriver(driverService);
driver.Navigate().GoToUrl(new Uri("http://www.yellowpages.com/los-angeles-ca/pizza?g=Los+Angeles%2C+CA"));
string url = driver.Url;
var next = driver.FindElementByCssSelector(".next");
next.Click();            
string newUrl = driver.Url;

The "next" link is found and clicked but I do not get the new URL after calling next.Click().

Other pages work fine. I am only having problems on yellowpages right now.

Any ideas?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
jimbo
  • 582
  • 1
  • 11
  • 28
  • 1
    You probably need to wait since the button triggers an ajax request and only then loads the next page. – Artjom B. Oct 26 '14 at 12:30
  • I have tried to wait like mentioned in this thread http://stackoverflow.com/a/25745256/1718124 without success. URL didn't change. – jimbo Oct 26 '14 at 15:07
  • 1
    Try setting `driverService.SslProtocol = "tlsv1";` before passing it to the driver. Can you try with and without the wait? See for source: http://stackoverflow.com/a/26565942/1816580 – Artjom B. Oct 26 '14 at 15:43
  • That works! Even without the wait extension. Thank you! – jimbo Oct 26 '14 at 16:10
  • It seems that a part of the JS necessary for the button to work, is loaded through an https url. – Artjom B. Oct 26 '14 at 16:13
  • possible duplicate of [Selenium Webdriver + PhantomJS remains at about:blank for a specific site](http://stackoverflow.com/questions/20705027/selenium-webdriver-phantomjs-remains-at-aboutblank-for-a-specific-site) – Artjom B. Oct 26 '14 at 16:14
  • @ArtjomB. can you please elaborate on the solution you suggested? – Johnny Oct 27 '14 at 10:03
  • 1
    @StasS Do you mean the reason? Some sites removed SSLv3 from their servers because of POODLE. Therefore the PhantomJS ssl protocol should be set to TLSv1 so that those sites are loaded. But this should be clear from the linked answer. – Artjom B. Oct 27 '14 at 10:11

2 Answers2

1

Try this for clicking on the web element instead of using click():

JavascriptExecutor js = (JavascriptExecutor)driver;

js.executeScript("arguments[0].click();", next);
James Zaghini
  • 3,895
  • 4
  • 45
  • 61
  • 1
    This will work, I have a custom function called click where I use click() for chrome, FF and for phantomjs I use javaScript..FYI the code is in Java – user3381093 Oct 20 '16 at 20:52
0

Make sure you have turned on console output, so you could see the exact error:

service.HideCommandPromptWindow = true;

I had similar problem, and when i turned on console output I noticed the following error: "can't find variable: __doPostBack".

In my case, that was because of site declined defaut Phantom's user agent, so I had to change it (based on this answer).

Community
  • 1
  • 1
Illidan
  • 4,047
  • 3
  • 39
  • 49