0

I have the following anchor tag with this href:

<a id="bodyContent_gv_list_lbtn_personname_2" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$bodyContent$gv_list$ctl04$lbtn_personname&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, true))"><span class="articleText">element</span></a>

I need to provide a link directly to the page this href is referncing. I would usually use a selenium driver and use get_attribute('href') of an anchor element. However, when I do that I am left with the script as you see writen. When the element is clicked manually the URL in my browser does not change (so I cannot construct it). Is there a way to turn this javascript script into a URL that directly links to the page which it is referncing?

I tried checking if the URL can be manually constructed (but it does not change when the link is clicked).

There is nothing in the useful in XHR or JS in the network tab

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Try following: `href = element.get_attribute("href"); if href.startswith("javascript:"): href=href.split("javascript:", 1)[1]; result = driver.execute_script("return " + href); print(result)` (split by `;`) – Jurakin Feb 16 '23 at 14:46
  • Please provide us url of the site so we can test our code – Jurakin Feb 16 '23 at 17:57
  • It's a post (postback?), so the url is the action of the form but you also need the form vars to make it work – pguardiario Feb 18 '23 at 00:23

2 Answers2

0

There is no URL. The href is calling a JS method that is updating something. That's why you don't see the page/URL change on click.

JeffC
  • 22,180
  • 5
  • 32
  • 55
0

No, unfortunately you can't translate/construct a direct link to the page this href is referring through the WebForm_DoPostBackWithOptions


PostBackOptions

The PostBackOptions class allows controls to emit client-side script that initiates a postback event. The PostBackOptions class also provides a reference to the control that initiated the postback event through the TargetControl property. The postback event is created based on the options specified in the PostBackOptions object passed in to the ClientScriptManager.GetPostBackEventReference method.

There is no official documentation on the parameters of WebForm_PostBackOptions but the javascript declaration is more or less the same as follows:

function WebForm_PostBackOptions(eventTarget, eventArgument, validation, validationGroup, actionUrl, trackFocus, clientSubmit)

Normally, a postback to the server is initiated by elements such as a Submit button or an Image button. However, by emitting client-side JavaScript, different controls can initiate a postback event.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352