0

Hi I am new to Selenium Webdriver. I can successfully open a webpage and find elements on it.

In one case I have noted that there is a link on a page that becomes clickable after a while. In Firebug on the Script tab, I can see the code for the javascript that does the timer function.

But using Selenium Webdriver if I issue:

driver.PageSource

I cannot see the source code for the Javascript. Delaying for 30 seconds before requesting the source makes no difference. I have tried finding it with various By options using:

driver.FindElement

and so on, but it isnt there.

How does firebug manage to find and show the Javascript source code? Is there a way that I can coerce Selenium Webdriver to return all code referenced by the page?

Or is there a better approach?

Thanks for any advice!

EDIT---------------------

I tried the following in Firefox:

Dim Driver2 As IWebDriver = New Chrome.ChromeDriver
Driver2.Url = "http://mypage" 
Dim js As IJavaScriptExecutor = TryCast(Driver2, IJavaScriptExecutor)
Dim title As String = DirectCast(js.ExecuteScript("return JSON.stringify(window)"), String)

and I got

Permission denied to access property 'toJSON'

I read that this wont work in firefox so I tried in Chrome, and got

Blocked a frame with origin "http://mypage" from accessing a cross-origin frame

and from there no solutions because according to this its a security restriction, apparently you can't access an with Javascript

I'm starting to think Im a bit out of my depth here.

Community
  • 1
  • 1
TripleAntigen
  • 2,070
  • 1
  • 29
  • 41

1 Answers1

0

PageSource probably doesn't return an exact snapshot of the DOM & etc.

You can instead inspect javascript using driver.executeScript() but the burden of analyzing the return object may be discouraging.

Regardless - Here's a contrived example:

Object result = driver.executeScript("return JSON.stringify(window)");
System.out.println(result.toString());
Huy
  • 1,849
  • 18
  • 18