Hey there, I'm trying out a script in perl language using Selenium Chrome Driver as engine. It's a fairly simple code but I got to a part that kept blocking my process for 2-3 days now and I can't seem to get around it. The script consists into logging into an online game account and opening the main page (it's pretty simple as I said, after all it's just exercises for me before I get the hand of it).
use feature ':5.10'; use strict; use warnings; use Selenium::Chrome; use Selenium::Remote::WebElement; my $driver = Selenium::Chrome->new; my $a = 'email'; #write email here my $b = 'password'; #write password here my $login_url = "link/login/"; #link to the website (link is a substi +tute to the actual URL which was considered spam so i just wrote "lin +k") $driver->get( $login_url ); #navigate to the website my $name = $driver->find_element("//input[@name='mailAddress']"); $name->send_keys( $a ); #find and input mail address my $password = $driver->find_element("//input[@name='password']"); $password->send_keys( $b ); #find and input password my $Login_button = $driver->find_element("//input[@value='Login']"); $Login_button->click(); #find and click login button

So far the code is perfect. Now, after reaching this part the struggles started. After logging in an image appears with a ''My Page'' button. This button leads to the my page menu (duh) where I want my script to end at. The source code for the button is below:

<a id="enterBtn" class="push-motion0 js-onceLink" href="link/mypage?t=1pSX7e.3KXy.asX.2k42h.1klg0.280f08.H" style="user-select: none; touch-action: pan-y; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></a>

I've tried several things to get past this but I just can't get to navigate to My page and/or ''click'' the button. The thing is the http URL has a base part

"link/mypage?t="

and a token part

"1pSX7e.3KXy.asX.2k42h.1klg0.280f08.H".

The token part changes EVERY time you reopen the page so I CANNOT (or I don't know how to) assign the url to a variable like I did above since it gives me an error upon entering the expired link.

Instead I tried to SEARCH for elements containing the partial link text:

my $my_page = $driver->find_element("//a[@href='link/mypage?t=]"); my $href = $my_page->get_attribute("href"); $driver->get($href); <>;

Also tried 'click' instead of 'get' with same result.

The script stops at the current page without navigating to "My page" menu. The error bellow appears in the .bat that I use to execute the command.

"Use of uninitialized value in substitution iterator at C:/Perl64/site/lib/Selenium/Remote/Commands.pm line 437."

I just can't seem to get past this element and finally open "my page" menu. It has something to do with XPath but I think I'm missing something (simple yet essential).


In reply to Issues Fetching URL with a variable token by Petroza

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.