E
E
Evgeny_A2019-10-11 22:21:42
selenium
Evgeny_A, 2019-10-11 22:21:42

How to get url after click on object with onclick in Selenium?

Hello!
There are sites that don't have explicit links in the HTML body. I came across these links:

<div onclick="openBook(2389);">
</div>

If you click on such a div, then there will be a GET request like this sit.com/book.php?id=2389, which returns a new page in its entirety. It is from this new page that I will need to take the content. The question is how to collect all the links inside the onclick but not load the content that is inside? I want to collect all-all links in one list and then recursively parse each page.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daria Motorina, 2019-10-11
@glaphire

Algorithm:
1. Find all elements with onclick on the page (if the majority of the site has such a structure)
Example
2. Get the ID from the content of the onclick attribute (i.e. 2389 from openBook(2389);)
3. Blind from a piece of link and ID a full-fledged link and add it to the array of final links

currrent_link = "sit.com/book.php?id=" + current_id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question