lpowers has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I'm trying to click on a button/link (to post a product) on a Google My Business page. It appears to be a javascript activated div. I just can't get it to work. If I use a $mech->click function like this:
$mech->click( { selector => '#dcrd-31 > div > div > div.U26fgb.If.fx.s +r.Bj.B580Hc.vDGRIe.Aw > div.wo.ida', single => 1 } );
I usually get an error saying "No elements found for CSS selector"
If I use the xpath equivalent like this:
$mech->click( { xpath => '//*[@id="dcrd-31"]/div/div/div[1]', single = +> 1 } );
It seems to activate the button and the div pops open for the product listing information to be entered. This seems good, except that my perl program hangs at this point. The next line after $mech->click never runs.
I know somebody else posted about having hanging issues when they tried to go to the same URL twice (I think it turned out to be bug where Mechanize::Chrome couldn't click to the same page/URL). Not sure if this is related or not.
This is the source code for the div that contains the 'post' button:
<div role="button" class="U26fgb If fx sr Bj B580Hc vDGRIe Aw" jscontr +oller="VXdfxd" jsaction="click:cOuCgd; mousedown:UX7yZ; mouseup:lbsD7 +e; mouseenter:tfO1Yc; mouseleave:JywGue;touchstart:p6p2H; touchmove:F +wuNnf; touchend:yfqBxc(preventMouseEvents=true|preventDefault=true); +touchcancel:JMtRjd;focus:AHmuwe; blur:O22p3e; contextmenu:mg9Pef;" js +shadow="" jsname="nFHyHb" aria-disabled="false" tabindex="0" data-log +-cta="20"><div class="nh he" jsname="ksKsZd" style="top: 17px; left: +12px; width: 155px; height: 155px;"></div><div class="wo ida"></div>< +content class="T4"><span class="tr Jh"><div class="uY5Ftd"><svg viewB +ox="0 0 24 24"><path d="M3 3v18h18V3H3zm3 3h12v6H6V6zm12 12H6v-1h12v1 +zm0-2H6v-1h12v1z"></path><path fill="none" d="M0 0h24v24H0z"></path>< +/svg></div><span class="FIWWyb">Create post</span></span></content></ +div>
What would be the proper way to "click" this div?
Thanks much!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How click on javascript div link - WWW::Mechanize::Chrome
by marto (Cardinal) on Sep 04, 2018 at 09:43 UTC | |
|
Re: How click on javascript div link - WWW::Mechanize::Chrome
by Corion (Patriarch) on Sep 04, 2018 at 06:49 UTC |