๋ฐ˜์‘ํ˜•

ํฌ๋กฌ ๋“œ๋ผ์ด๋ฒ„ ์—…๋ฐ์ดํŠธ

ํฌ๋กฌ ๋ธŒ๋ผ์šฐ์ € ๊ธฐ๋ฐ˜์œผ๋กœ ํฌ๋กค๋ง ํ”„๋กœ๊ทธ๋žจ ๊ฐœ๋ฐœ ์‹œ ํ˜„์žฌ ์‹œ์Šคํ…œ์— ์„ค์น˜๋˜์–ด ์žˆ๋Š” ํฌ๋กฌ ๋ธŒ๋ผ์šฐ์ €์˜ ๋ฒ„์ „๊ณผ, ์‹คํ–‰๋˜๋Š” ํ”„๋กœ๊ทธ๋žจ์˜ ๋ฒ„์ „์„ ๋งž์ถ”๋Š” ์ž‘์—…์ด ์ฐธ ๊ท€์ฐฎ์•˜์Šต๋‹ˆ๋‹ค.

๋งŒ์•ฝ, ๋ฒ„์ „์ด ๋งž์ง€ ์•Š์œผ๋ฉด ๋“œ๋ผ์ด๋ฒ„ ๋ฒ„์ „์ด ์ผ์น˜ํ•˜์ง€ ์•Š์•„ ๋™์ž‘ํ•œ๋‹ค๋Š” ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ ์ด๋ฅผ ๋Œ€์ฒ˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•„๋ž˜์˜ ํฌ์ŠคํŒ…์— ์˜ฌ๋ฆฐ ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

[์…€๋ ˆ๋‹ˆ์›€/Selenium, C#] ChromeDriver ๋ฒ„์ „ ์—๋Ÿฌ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

 

[์…€๋ ˆ๋‹ˆ์›€/Selenium, C#] ChromeDriver ๋ฒ„์ „ ์—๋Ÿฌ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

ํฌ๋กฌ ๋“œ๋ผ์ด๋ฒ„ ๋ฒ„์ „ ์˜ค๋ฅ˜ ํ˜„์ƒ ํฌ๋กฌ ๋“œ๋ผ์ด๋ฒ„๋ฅผ ์ด์šฉํ•œ ํฌ๋กค๋ง ํ”„๋กœ๊ทธ๋žจ ์ œ์ž‘ ์‹œ ์•„๋ž˜์˜ ๋ฉ”์‹œ์ง€๋Š” ํ•œ ๋ฒˆ์ฏค์€ ๋ดค์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค. session not created: This version of ChromeDriver only supports Chrome version 85 (Session

luckygg.tistory.com

์ตœ๊ทผ ๋“ค์–ด ์ด ๋ฐฉ๋ฒ•๋„ ์ž˜ ์•ˆํ†ตํ•˜๋Š” ๊ฒƒ์„ ํ™•์ธํ–ˆ๋Š”๋ฐ์š”. ํฌ๋กฌ ๋ธŒ๋ผ์šฐ์ € ๋ฒ„์ „์ด ์ตœ์‹ ์ด์ง€๋งŒ, ํฌ๋กฌ ๋“œ๋ผ์ด๋ฒ„ ๋‹ค์šด๋กœ๋“œ ํŽ˜์ด์ง€์—๋Š” ๋ฒ„์ „๊ณผ ์ผ์น˜ํ•˜๋Š” ํŒŒ์ผ์ด ์—†์–ด ์ œ๋Œ€๋กœ ๋™์ž‘ํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.

์‚ฌ์‹ค, ์ด๋ณด๋‹ค ๋” ๊ฐ„ํŽธํ•œ ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๋‹ค. ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰ ์‹œ ์ž๋™์œผ๋กœ ํฌ๋กฌ ๋“œ๋ผ์ด๋ฒ„๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. ๊ทธ๋Ÿผ ๋” ์ด์ƒ ๊ท€์ฐฎ๊ฒŒ ์ง์ ‘ ๋‹ค์šด๋กœ๋“œํ•  ํ•„์š”๊ฐ€ ์—†์ง€์š”.

๋ณธ๋ฌธ์—์„œ ์ฐจ๊ทผ์ฐจ๊ทผ ์„ค๋ช…ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

๋”ฐ๋ผ ํ•˜๊ธฐ

1. C# ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ธฐ

์ฝ˜์†”์ด๋“  WinForm์ด๋“  ์ƒ๊ด€ ์—†์Šต๋‹ˆ๋‹ค. ์‚ฌ์šฉํ•˜๊ธฐ ํŽธํ•œ ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ์ €๋Š” WinForm ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค.

2. NuGet์—์„œ Selenium ํŒจํ‚ค์ง€ ์„ค์น˜ํ•˜๊ธฐ

ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ ํ›„ Visual Studio ์ƒ๋‹จ ๋ฉ”๋‰ด ์ค‘ ๋„๊ตฌ > NuGet ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ์ž > ์†”๋ฃจ์…˜์šฉ NuGet ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ ๋ฉ”๋‰ด๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

NuGet-ํŒจํ‚ค์ง€-๊ด€๋ฆฌ-๋ฉ”๋‰ด
NuGet ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ ๋ฉ”๋‰ด

์ฐพ์•„๋ณด๊ธฐ ํƒญ์—์„œ ๊ฒ€์ƒ‰๋ž€์— selenium์„ ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค.

selenium-ํŒจํ‚ค์ง€-๊ฒ€์ƒ‰
selenium ํŒจํ‚ค์ง€ ๊ฒ€์ƒ‰

๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ์—์„œ Selenium.WebDriver์™€ Selenium.Support ํŒจํ‚ค์ง€๋ฅผ ํ”„๋กœ์ ํŠธ์— ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋‹ค์‹œ ๊ฒ€์ƒ‰ ๋ž€์— web driver manager๋ฅผ ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค.

web-driver-manager-ํŒจํ‚ค์ง€-๊ฒ€์ƒ‰
web driver manager ํŒจํ‚ค์ง€ ๊ฒ€์ƒ‰

WebDriverManager ํŒจํ‚ค์ง€๋ฅผ ํ”„๋กœ์ ํŠธ์— ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

์ฃผ์˜
 
 

๋งŒ์•ฝ, Selenium.WeDriver.ChromeDriver ํŒจํ‚ค์ง€๋ฅผ ๊ฐ™์ด ์„ค์น˜ํ•˜๋ฉด ๋“œ๋ผ์ด๋ฒ„ ์ถฉ๋Œ์ด ๋ฐœ์ƒํ•ด ํฌ๋กฌ ๋“œ๋ผ์ด๋ฒ„๊ฐ€ ์ผ์น˜ํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ์˜ค๋ฅ˜๊ฐ€ ๊ณ„์†ํ•ด์„œ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

3. ์ฝ”๋“œ ๊ตฌํ˜„

๊ธฐ๋ณธ์ ์ธ ์ฝ”๋“œ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

//๊ธฐ๋ณธ namespace ์ƒ๋žต
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using WebDriverManager;
using WebDriverManager.Helpers;
using WebDriverManager.DriverConfigs.Impl;

namespace ExamSelenium
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            try
            {
                ChromeDriverService driverService = null;
                ChromeOptions options = null;
                ChromeDriver driver = null;

                //ํฌ๋กฌ ๋“œ๋ผ์ด๋ฒ„ ์ž๋™ ์—…๋ฐ์ดํŠธ
                new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser);

                driverService = ChromeDriverService.CreateDefaultService();
                driverService.HideCommandPromptWindow = true;

                options = new ChromeOptions();
                options.AddArgument("disable-gpu");

                driver = new ChromeDriver(driverService, options);

                driver.Navigate().GoToUrl("https://www.naver.com");
            }
            catch(Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }
    }
}

Chrome ๊ด€๋ จ ๊ฐ์ฒด๋Š” ์˜ˆ์ „์— ์„ค๋ช…ํ•œ ๋‚ด์šฉ๊ณผ ๋™์ผํ•˜๊ณ , 24๋ฒˆ์งธ ๋ผ์ธ์˜ DriverManager() ๋ถ€๋ถ„์ด ํ•ต์‹ฌ์ž…๋‹ˆ๋‹ค. ์ด ์ฝ”๋“œ๊ฐ€ ์‹คํ–‰๋˜๋ฉด ํ˜„์žฌ ์‹œ์Šคํ…œ์— ์„ค์น˜๋˜์–ด ์žˆ๋Š” ๋ธŒ๋ผ์šฐ์ €์™€ ์ผ์น˜ํ•˜๋Š” ํฌ๋กฌ ๋“œ๋ผ์ด๋ฒ„๊ฐ€ ์ž๋™์œผ๋กœ ์ค€๋น„๋ฉ๋‹ˆ๋‹ค.

ํฌ๋กฌ ๋“œ๋ผ์ด๋ฒ„ ์—…๋ฐ์ดํŠธ ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์—ฌ๋Ÿฌ ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๋‹ค.

//ํŠน์ • ๋ฒ„์ „
new DriverManager().SetUpDriver(new ChromeConfig(), "2.25")

//ํŠน์ • ์•„ํ‚คํ…์ฒ˜
new DriverManager().SetUpDriver(new ChromeConfig(), "Latest", Architecture.X32)

//ํŠน์ • ๋ฒ„์ „ ๋ฐ ํŠน์ • ์•„ํ‚คํ…์ฒ˜
new DriverManager().SetUpDriver(new ChromeConfig(), "2.25", Architecture.X64)

//๋ธŒ๋ผ์šฐ์ €์™€ ์ผ์น˜ํ•˜๋Š” ๋ฒ„์ „(Chrome, Edge, Firefox, Internet Explorer๋งŒ ํ•ด๋‹น):
new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser);

๊ทธ ์™ธ WebDriverManager์— ๋Œ€ํ•ด ๋” ๊ถ๊ธˆํ•˜๋‹ค๋ฉด ์•„๋ž˜ GitHub ํŽ˜์ด์ง€๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š”.

https://github.com/rosolko/WebDriverManager.Net

 

GitHub - rosolko/WebDriverManager.Net: Automatic Selenium Webdriver binaries management for .Net

Automatic Selenium Webdriver binaries management for .Net - GitHub - rosolko/WebDriverManager.Net: Automatic Selenium Webdriver binaries management for .Net

github.com

๋ฐ˜์‘ํ˜•