I was doing an automatic test using Python + Selenium + Chrome, but when I accessed the smartphone screen, I was redirected to the PC screen and sometimes I could not test the smartphone screen.
Therefore, I investigated whether it can be automated well using Chrome's smartphone mode, so I will summarize the method.
Summarizing the results of the investigation, it seems that it can be started in smartphone mode by executing the following program. (It works even if you copy and paste it as it is)
smp_mood.py
from selenium import webdriver
import time
def smp_mood():
url = "https://www.yahoo.co.jp/"
mobile_emulation = { "deviceName": "Galaxy S5" }
options = webdriver.ChromeOptions()
options.add_experimental_option("mobileEmulation", mobile_emulation)
driver = webdriver.Chrome(options=options)
driver.get(url)
time.sleep(2)
smp_mood()
The above is accessing the Yahoo site with "Galaxy S5".
Of the above program
"Galaxy S5"
It is possible to change to the terminal you want to use by rewriting.
For the device that can be switched, right-click on Chrome and press "Verify". After that, press the smartphone mark on the upper right of the screen to change to the smartphone mode, and then press "Terminal name> Edut ..." displayed on the upper left of the screen to display the list of terminals that can be changed.
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
Based on the above
"iPhone 6"
You can change the target terminal by rewriting as.
Recommended Posts