Unanswered question

Can't execute JS code with NLWebDriver on C#

Ok, so I'm writing a Selenium script in C# so I can measure some load times and I need to scroll to the bottom of a page, so I'm using this piece of code "((IJavaScriptExecutor)driver).ExecuteScript("window.scrollTo(0, document.body.scrollHeight);");" but it return an error "System.InvalidCastException: 'Unable to cast object of type 'NeoLoadSelenium.neoload.wrapper.NLWebDriver' to type 'OpenQA.Selenium.IJavaScriptExecutor'.'". Does anyone have an idea how to fix this so I could scroll to the bottom of the page.

Valentin R.
Valentin R.

Valentin R.

Level
0
13 / 100
points

Answers

Alexis N.
Alexis N.

Alexis N.

Level
2
858 / 2000
points
Team

The Selenium wrapper of NeoLoad does not support ExecuteScript.
So you need to execute the script to your original driver.

For example:

var driver = new FirefoxDriver(profile);
var nlDriver = NLWebDriverFactory.NewNLWebDriver(driver, "Selenium");

nlDriver.StartTransaction("home");
nlDriver.Url = "http://ushahidi.demo.neotys.com/";;

nlDriver.StartTransaction("reports");
nlDriver.FindElement(By.Id("mainmenu")).FindElements(By.TagName("a"))[1].Click();

driver.ExecuteScript("window.scrollTo(0, document.body.scrollHeight);");

driver is the original driver and nlDriver is the NeoLoad wrapper.