0

(Previous thread)

(Thread for the same problem)

I want to extract information from a website, but in order to do that I need to login. Basically I can't authenticate with a HTTP/Web/Server request so I have to do it via browser, using WebDriver Selenium (Chrome). Now since the information can't be found through "view source-code", driver.PageSource doesn't work for example. Now when I do what has been suggested in the mentioned thread, I still get the wrong source code (there has also been the same problem reported in the comments). I need to get the code from the Inspector.

Any ideas? Thanks in advance!

    class Program
    {
        static void Main(string[] args)
        {
            string url = "link";
            IWebDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl(url);

            IWebElement email = driver.FindElement(By.Id("login-email-input-field")); 
            IWebElement password = driver.FindElement(By.Id("login-password-input")); 

            email.SendKeys("email");
            password.SendKeys("password");
            IWebElement login = driver.FindElement(By.Id("login-btn"));
            login.Click();

            driver.Navigate().GoToUrl(url);

            Thread.Sleep(10000);

            //Trying to get the inspect element code here
            IWebElement element = driver.FindElement(By.Id("id"));
            var html = element.GetAttribute("innerHTML");
            Console.WriteLine(html);

        }
    }
}
  • What DO you get if not the inner elements of the element you are evaluating? Coz that is what you get with the **innerHTML** attribute. And what exactly were you expecting to get, btw? – String.Empty Nov 27 '20 at 11:22
  • And why you navigate to the same URL after logging in? Wouldn't that bring up the login page again? And you might as well just replace your for loop of 5 Thread.Sleep(2000) cmds for a single Thread.Sleep(10000), ehehe. What is the purpose of a loop there if all you do is wait? – String.Empty Nov 27 '20 at 11:42
  • @String.Empty I want to grab the code inside the Inspector. Not the "view source-code" stuff since they are different from their content. Also I navigate to the same URL because after logging inI get to the homepage, and opening it up again will make me redirect to the page I want without logging in again. You're right about that pause though. –  Nov 27 '20 at 12:17
  • The code inside the inspector is basically all the elements in the page. What you are doing is grabbing ONE element (that has ID = id) and retrieving the code for its **inner** elements. If the element you are grabbing is not the root of the page, then what you get will obviously not be like what you see in the inspector. And even if it is the root, you won't see the code for that element itself. – String.Empty Nov 27 '20 at 18:59
  • Go to the page in question, launch developer tools, go to Console, and type the following query: `$$("#id").map(e => e.innerHTML)` Post what you get with that (just the beginning, say first 25 or so characters). Then post what you get with your code (also just the first 25 characters should be fine). This way we can compare both methods. – String.Empty Nov 27 '20 at 19:06

0 Answers0