์ ๋ ๋์ - ์๋๋ก์ด๋ ๋ชจ๋ฐ์ผ ํฌ๋กฌ ์กฐ์
๋๋ฐ์ด์ค๊ฐ ํ ๊ฐ์ธ ๊ฒฝ์ฐ
# -*- coding: utf-8 -*-
from selenium import webdriver
import time
options = webdriver.ChromeOptions()
options.add_experimental_option('androidPackage', 'com.android.chrome')
driver = webdriver.Chrome(options=options)
driver.implicitly_wait(15)
driver.get('https://www.naver.com')
time.sleep(1)
print(driver.current_url)
driver.execute_script('alert(1)')
๋์ค์ ์๊ฒ๋ ์ฌ์ค์ธ๋ฐ driver = webdriver.Chrome('chromedriver.exe', options=options)์์ 'chromedriver.exe'๋ ์๋ต์ด ๊ฐ๋ฅํ๋ค.
์ถ์ฒ:
Is it possible to open a mobile browser with Selenium WebDriver?
I know it is possible to open a desktop web browser with Selenium WeDriver. The following lines written in Java allows doing so: WebDriver webDriverChrome = new ChromeDriver(); webDriverChrome.get(
sqa.stackexchange.com
๋๋ฐ์ด์ค๊ฐ ์ฌ๋ฌ๊ฐ์ธ ๊ฒฝ์ฐ
options์ androidDeviceSerial์ ์์ฑ ๊ฐ์ผ๋ก ๋๋ฐ์ด์ค ๊ณ ์ ์๋ฆฌ์ผ์ ์ ๋ ฅํด์ค๋ค.
# -*- coding: utf-8 -*-
from selenium import webdriver
import time
options = webdriver.ChromeOptions()
options.add_experimental_option('androidPackage', 'com.android.chrome')
options.add_experimental_option('androidDeviceSerial', '0715f764e18f1532')
driver = webdriver.Chrome(options=options)
driver.implicitly_wait(15)
driver.get('https://www.naver.com')
time.sleep(1)
print(driver.current_url)
driver.execute_script('alert(1)')
adb devices๋ก ๋๋ฐ์ด์ค์ ๊ณ ์ ์๋ฆฌ์ผ ๊ฐ์ ์์๋ผ ์ ์์.
์ถ์ฒ:
https://chromedriver.chromium.org/getting-started/getting-started---android
ChromeDriver - WebDriver for Chrome - Android
Dependencies
chromedriver.chromium.org
์ฑ ํ๋ ์ด์ด์์ ์คํํ๋๋ฐ ํฌ๋กฌ ์ฑ์ด ๊บผ์ง๋ ๊ฒฝ์ฐ
์ ๊ทธ๋ฐ์ง๋ ์์ธํ ๋ชจ๋ฅด๊ฒ ์ง๋ง ์ ์๋ผ๋ ์ฑ ํ๋ ์ด์ด(๋ น์ค)์ ์กฐ์์ ํ์ง ์์ผ๋ฉด adb ์ฐ๊ฒฐ์ด ์๋๋ค.
๊ทธ๋ด๋ adb shell๋ก ์ฐ๊ฒฐ์ด ์๋๋ค๋ฉด ์ฑ ํ๋ ์ด์ด๋ฅผ ์ ๊น ์กฐ์ํด์ ํ์ฑํ ์์ผ์ค๋ค.
C# Selenium์์ ์ฌ์ฉํ๊ธฐ
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddAdditionalCapability("androidPackage", "com.android.chrome");
driver = new ChromeDriver(defaultService, chromeOptions);
๋ง์ฝ argument๋ฅผ ์ฐพ์ ์ ์๋ ์ค๋ฅ๊ฐ ๋ฌ๋ค๋ฉด Selenium ๋ชจ๋์ ์ฌ์ค์นํ๊ฑฐ๋ adb๋ฅผ ์ต์ ๋ฒ์ ์ผ๋ก ์ค์น๋ฅผ ๊ถ์ฅํ๋ค.