dags att checka in

This commit is contained in:
2021-08-02 12:41:02 +02:00
parent 5648effc9a
commit 668659bf20
34 changed files with 1092 additions and 5 deletions

41
Selenium/Program.cs Normal file
View File

@ -0,0 +1,41 @@
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using System;
using System.Drawing.Imaging;
using System.IO;
namespace Selenium
{
class Program
{
static void Main(string[] args)
{
// Initialize the Chrome Driver
using (var driver = new ChromeDriver())
{
// Go to the home page
driver.Navigate().GoToUrl("http://testing-ground.webscraping.pro/login");
// Get the page elements
var userNameField = driver.FindElementById("usr");
var userPasswordField = driver.FindElementById("pwd");
var loginButton = driver.FindElementByXPath("//input[@value='Login']");
// Type user name and password
userNameField.SendKeys("admin");
userPasswordField.SendKeys("12345");
// and click the login button
loginButton.Click();
// Extract the text and save it into result.txt
var result = driver.FindElementByXPath("//div[@id='case_login']/h3").Text;
File.WriteAllText("result.txt", result);
// Take a screenshot and save it into screen.png
driver.GetScreenshot().SaveAsFile(@"screen.png", ScreenshotImageFormat.Png);
}
}
}
}