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!


In reply to How click on javascript div link - WWW::Mechanize::Chrome by lpowers

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.