0

I want to get the URL I am re-directed to when I click one button on the website, and still stay on the same page instead of being redirected. The button is not a simple hyperlink and will trigger a complex Javascript function.

click() does not work for me

I refer to Selenium get URL of "a" Tag without href attribute and Selenium: Getting ultimate href/link without clicking on it when it's a javascript call, which shows that the button has to be clicked to get the URL. Of course, I can click() the button and use 'driver.current_url', but in this way I am redirected to a new URL. I do not want the redirection since I have more things to do on the current page and want to stay on the same page. I can not use CTRL + click to open the new page in a new tab, either.

My idea

I read about how to find the source Javascript code (How to find what code is run by a button or element in Chrome using Developer Tools), but I found the codes too complex for me. Should I find the codes that produce the URL?

I wonder can I just "fork" the current page? Or something like simulating/executing the Javascript code in a separate sandbox? I am using python.

hellohawaii
  • 3,074
  • 6
  • 21
  • What's the page url? – Barry the Platipus Jun 05 '23 at 13:24
  • @BarrythePlatipus It is [this link](https://ke.wechess.cn/app/index.php?i=5&c=entry&m=xiangqi_lesson&do=search), I want to click the images and get the URLs they point to. – hellohawaii Jun 05 '23 at 13:32
  • The way forward here (slow but reliable) would be: 1 - a loop to scroll the page down until there are no more new items loaded; 2 - get the image unique identifiers (the image urls would do here) and save them in a set; 3 - click on the first image, let it load, get your info, save it, go back; scroll the page again, load the image lists, pop the image already visited, click on the next one; repeat until there are no more. – Barry the Platipus Jun 05 '23 at 13:43
  • @BarrythePlatipus Thank you for the comments. In fact, I want to avoid scrolling the page repeatedly. Is this possible? – hellohawaii Jun 05 '23 at 13:52
  • I'm sure it must be, however it would go against the minimal complexity budget principle. – Barry the Platipus Jun 05 '23 at 14:03

0 Answers0