Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everybody.

I'm preparing a webscraping of a website, is developed with Angular, and I don't know how to obtain the url where a tag < a > supouse to go (it has no src on the attributes).

The articles shows like this:

HTML
<a _ngcontent-ekg-c132="" tslitemroute="" class="ItemCardList__item ng-star-inserted" title="Title"></a>


If you click on each one the url is generated i guess on a JS script and a new tab is opened.



Is there any option to obtain the url once I call the click event?

Thanks in advance for your help.

What I have tried:

I'm trying to obtain it calling the click function:

C#
List<IWebElement> item = browser.FindElements(By.XPath("//a[@class='ItemCardList__item ng-star-inserted']")).ToList();
//Option 1
item[0].Click();

IJavaScriptExecutor js = (IJavaScriptExecutor)browser;
//Option 2
js.ExecuteScript("arguments[0].click();", item[0]);

I understand that this both works because the examples I found googling, but not sure how to work after that, maybe with handles?
Posted

1 solution

I have found a way, not really the best I want to but it works switching tabs and accessing the Url property:

C#
browser.SwitchTo().Window(browser.WindowHandles[1]);
string newWindowURL = browser.Url;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900