in reply to Re: No Elements Found with WWW::Mechanize::PhantomJS
in thread No Elements Found with WWW::Mechanize::PhantomJS

Thanks for this. Much appreciated. I've run the code with your suggestion but no matter what I do I keep getting the following error message when I use your suggested CSS selector:

No elements found for CSS selector '.tn-napsTable' at /usr/local/share/perl/5.22.1/WWW/Mechanize/Plugin/Selector.pm

And I get the error message: No elements found for /html/body/div4/main/div/div2/div/div/div1/div1/div2 when I run the xpath

Do you have any ideas as to what might be going wrong? I'm at a loss. Thank you again

  • Comment on Re^2: No Elements Found with WWW::Mechanize::PhantomJS

Replies are listed 'Best First'.
Re^3: No Elements Found with WWW::Mechanize::PhantomJS
by Corion (Patriarch) on Jun 04, 2018 at 10:50 UTC

    Maybe what PhantomJS sees as HTML content is different from what Firefox sees. In such cases, I usually print out what ->content returns and wonder why that is different from what my browser shows me.

    I admit that most of my development on that family of modules is focused on WWW::Mechanize::Chrome currently, but I'll try to reproduce your case once I get to an environment where I have PhantomJS installed.

Re^3: No Elements Found with WWW::Mechanize::PhantomJS
by Corion (Patriarch) on Jun 04, 2018 at 18:46 UTC

    This is really weird. For me, the below program works and outputs the HTML that I somewhat expect:

    use strict; use WWW::Mechanize::PhantomJS; use Data::Dumper; my $mech = WWW::Mechanize::PhantomJS->new( launch_arg => ['ghostdriver/src/main.js' ], ); $mech->get('https://www.racingpost.com/tipping/naps-table/'); sleep 5; my $cont= $mech->selector('.tn-napsTable', one => 1 ); my $content=$cont->get_attribute('innerHTML'); print $content; __END__ <div class="tn-napsTable__header"><div class="tn-napsTable__main"><div + role="but ton" tabindex="0" class="tn-napsTable__cell tn-napsTable__cell_header +tn-napsTab le__napsTipster_header"><!-- react-text: 15 -->Today's naps / Tipster< +!-- /react -text --></div><div role="button" tabindex="0" class="tn-napsTable__ce +ll tn-naps ...

    This is with PhantomJS v 2.1.1 on Windows and WWW::Mechanize::PhantomJS 0.18.

      Thank you so much for this. Works fine now that I've upgraded PhantomJS to v2.1.1. I was running the code before using an earlier version of PhantomJS v1.9 on Ubuntu 16.04