Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 2개 있습니다.)

Microsoft Edge (Chromium)을 대상으로 한 Selenium WebDriver 사용법

혹시나 있을까 싶어서 검색했더니 ^^ 나오는군요.

Microsoft WebDriver - Microsoft Edge (Chromium)
; https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/

현재 자신의 컴퓨터에 설치된 "Microsoft Edge (Chromium)" 버전을 확인 후 그에 맞는 edgedriver 파일을 다운로드하면 됩니다. 가령 제 경우에는 "77.0.197.0" 버전이기 때문에 다음의 파일을 사용했습니다.

edgedriver_win64.zip
; https://msedgedriver.azureedge.net/77.0.197.0/edgedriver_win64.zip

C# 프로젝트에서 사용하는 방법은 간단합니다. 우선, NuGet으로부터 패키지 2개를 설치하고,

Install-Package Selenium.WebDriver
Install-Package Selenium.Chrome.WebDriver

여느 ChromeDriver 사용법이랑 동일하지만, 단지 초기화 부분에만 "Microsoft Edge (Chromium)" 제품을 위한 배려만 추가하면 됩니다.

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        string platform = (IntPtr.Size == 8) ? "x64" : "x86";
        string path = Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), "lib", platform);

        ChromeOptions co = new ChromeOptions();
        co.BinaryLocation = @"C:\Program Files (x86)\Microsoft\Edge Dev\Application\msedge.exe";

        ChromeDriverService cds = ChromeDriverService.CreateDefaultService(path, "msedgedriver.exe");

        using (IWebDriver driver = new ChromeDriver(cds, co))
        {
            driver.Url = "https://www.sysnet.pe.kr";

            {
                IWebElement div = driver.FindElement(By.ClassName("leftCommentArea"));
                foreach (var item in div.FindElements(By.XPath(".//a")))
                {
                    Console.WriteLine(item.Text);
                }
            }

            Console.WriteLine("Press any key to exit...");
            Console.ReadLine();
        }
    }
}

(이 글의 예제 코드는 github - ChromiumEdgeSeleniumSample에서 제공합니다.)




[파이썬의 경우]

selenium 모듈 설치 후,

pip install -U selenium

아래의 사이트에서 이번엔 Chrome WebDriver를 다운로드하고,

Chrome - Web Driver 다운로드
; https://sites.google.com/a/chromium.org/chromedriver/downloads

압축을 해제한 chromedriver.exe 파일을 "c:/temp" 디렉터리(또는 원하는 경로)에 복사하고, 다음과 같이 코딩합니다.

from selenium import webdriver

options = webdriver.ChromeOptions()
# options.add_argument('headless')
options.add_argument('window-size=1920x1080')
driver = webdriver.Chrome('d:/Settings/selenium/chromedriver', options=options)

driver.implicitly_wait(3)
driver.get('https://www.naver.com')

# driver.quit()




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 8/15/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2021-01-02 08시12분
microsoft/playwright
 - Node.js library to automate Chromium, Firefox and WebKit with a single API
; https://github.com/microsoft/playwright

microsoft/playwright-dotnet
; https://github.com/microsoft/playwright-dotnet

using System.Threading.Tasks;
using Microsoft.Playwright;

class Program
{
    public static async Task Main()
    {
        using var playwright = await Playwright.CreateAsync();
        await using var browser = await playwright.Chromium.LaunchAsync(new() { Headless = false });
        var page = await browser.NewPageAsync();
        await page.GotoAsync("https://playwright.dev/dotnet");
        await page.ScreenshotAsync(new() { Path = "screenshot.png" });
    }
}

-----------------------------------

Say Goodbye to WebDriver: Modern Alternatives for Browser Automation – Part 1
; https://dev.to/serhii_korol_ab7776c50dba/say-goodbye-to-webdriver-modern-alternatives-for-browser-automation-part-1-4nna
정성태

... 181  182  183  184  185  186  187  188  189  190  191  [192]  193  194  195  ...
NoWriterDateCnt.TitleFile(s)
180정성태11/15/200518644    답변글 VS.NET IDE: 51.1. MSXML 6.0 정식 릴리스
174정성태10/31/200519544.NET Framework: 50. app.config 예시 [1]
173정성태10/30/200518225스크립트: 5. 스크립트 호출 관계
172정성태10/25/200526636.NET Framework: 49. ASP.NET 오류 유형 : 액세스가 거부되었습니다. [2]
171정성태11/14/200528388VC++: 19. 다국어 지원: setlocale( LC_TIME, "" ) 관련 [1]
170정성태11/14/200522974VS.NET IDE: 34. Visual SourceSafe 2005: Remote Internet Access over HTTP : 80 이외의 포트를 지정
206정성태2/1/200619525    답변글 VC++: 34.1. [추가]: Internet Access Plug-in 사용 시 유의 사항
168정성태11/14/200520596VS.NET IDE: 33. IIS 6.0 AppPool 설정 - Enable rapid-fail protection
169정성태10/14/200522301    답변글 VS.NET IDE: 33.1. Enable rapid-fail protection 상황 재현 방법
166정성태11/14/200519499.NET Framework: 48. IE를 죽이는 스크립트 소스
165정성태11/14/200520158.NET Framework: 47. MOM (Microsoft Operations Manager) 2005 서버 설치 가이드
164정성태11/14/200517349.NET Framework: 46. 도메인에 속한 컴퓨터의 Local Computer Policy 변경 방법
162정성태10/3/200519952.NET Framework: 45. VS.NET 2005 IDE에서 Web App를 .NET 2.0 (x64) 머신에 배포
161정성태11/14/200522756.NET Framework: 44. IIS 관리자에서 ASP.NET 탭이 없는 경우.
159정성태9/28/200518766VS.NET IDE: 32. Virtual Server 2005 64bit SP1 Beta 테스트 [2]
163정성태10/3/200516753    답변글 VS.NET IDE: 32.1. 왜...?
158정성태11/14/200519108VS.NET IDE: 31. SQL 2005 - A connection was successfully established with the server
157정성태9/21/200519010기타: 10. SQL2000 설치 시, Invalid Product Key 오류
156정성태9/16/200520984.NET Framework: 43. Wisptis.exe 프로세스
155정성태5/31/200517289.NET Framework: 42. .NET Installer Class에서 Install 메서드 - 설정 사항들 알아내는 코드
154정성태5/13/200516267VS.NET IDE: 30. Windows 2003 for x64에 추가된 레지스트리 Run 노드
152정성태5/5/200519665VC++: 18. VC++ 7.0에서부터 ? : 연산자 처리가 바뀌었습니다.
153정성태5/12/200519917    답변글 VC++: 18.1. VC++ 8.0에서부터 바뀐 CRT 소개
151정성태5/5/200522829VC++: 17. DLL에 export 된 C++ 클래스 멤버 함수 파라미터형 정보 알아내는 방법
150정성태5/5/200523888.NET Framework: 41. 태그 사이의 값을 추출하는 정규식
149정성태5/5/200520407.NET Framework: 40. 데이터그리드에서 콤보박스 쓸 수 있는 방법
... 181  182  183  184  185  186  187  188  189  190  191  [192]  193  194  195  ...