Hi,
I have been trying different things to get this Selenium to work but no luck.
I created a new WPF project and downloaded the Selenium Nugget packages V2.53.1 Support and WebDriver.
This is the code I use:
IWebDriver driver = new InternetExplorerDriver("C:\\Program Files\\SeleniumWebPagetester");
driver.Navigate().GoToUrl("D:\\test.html");
var src = driver.PageSource; //showes the html page -> works
var test = driver.FindElement(By.Id("aspnetForm")); //An unhandled exception of type 'OpenQA.Selenium.NoSuchElementException' occurred in WebDriver.dll
var testy = driver.FindElement(By.Id("aspnetForm"), 30); //'OpenQA.Selenium.NoSuchElementException'
var tst = driver.FindElement(By.XPath("//*[@id=\"lx-home\"]"), 30); //'OpenQA.Selenium.NoSuchElementException'
driver.Quit();
The web page:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<form action="#" id="aspnetForm" onsubmit="return false;">
<section id="lx-home" style="margin-bottom:50px;">
<div class="bigbanner">
<div class="splash mc">
<div class="bighead crb">LEAD DELIVERY MADE EASY</div>
</div>
</div>
</section>
</form>
</body>
</html>
Things I tried:
The timer, I waited 30 seconds before it starts looking for the ID to be sure the page is loaded -> No element exception
PageSource, I checked if the html page was loaded correctly. The full page gets correcty loaded, no issue here imo.
Xpath, also doesn't find any id or class.
Xpath gives the correct element when I use the HTMLWeb Class -> Xpath WORKS
string Url = "D:\\test.html";
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load(Url);
var element = doc.DocumentNode.SelectNodes("//*[@id=\"lx-home\"]"); //WORKS
What am I doing wrong here?