dags att checka in
This commit is contained in:
41
Selenium/Program.cs
Normal file
41
Selenium/Program.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
Selenium/Selenium.csproj
Normal file
17
Selenium/Selenium.csproj
Normal file
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Selenium.Chrome.WebDriver" Version="85.0.0" />
|
||||
<PackageReference Include="Selenium.Support" Version="3.141.0" />
|
||||
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
|
||||
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="92.0.4515.4300" />
|
||||
<PackageReference Include="Selenium.WebDriverBackedSelenium" Version="3.141.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user