Petroza has asked for the wisdom of the Perl Monks concerning the following question:
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).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Issues Fetching URL with a variable token
by 1nickt (Canon) on Oct 17, 2017 at 16:00 UTC | |
by Petroza (Novice) on Oct 17, 2017 at 17:12 UTC | |
|
Re: Issues Fetching URL with a variable token
by wjw (Priest) on Oct 17, 2017 at 20:07 UTC | |
|
Re: Issues Fetching URL with a variable token
by holli (Abbot) on Oct 17, 2017 at 20:01 UTC | |
by Petroza (Novice) on Oct 17, 2017 at 21:28 UTC | |
by holli (Abbot) on Oct 17, 2017 at 21:49 UTC | |
by Petroza (Novice) on Oct 17, 2017 at 22:06 UTC | |
|
Re: Issues Fetching URL with a variable token
by Petroza (Novice) on Oct 17, 2017 at 22:03 UTC |