Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use mobile browser in selenium without emulating the device?

I tried to write a script in python using selenium, that should automate uploading images to an image platform. However, the problem is, that the functionality for uploading pictures is only given, when you use a mobile browser (e.g. Safari on your iPhone). In a quick research, i found that selenium supports this, but as far as i understood it, this is only given if you emulate the device or connect a real device on your computer. Is there another way (maybe even another library?) for not having such an overhead (connecting or emulating the device), if you want to simulate an mobile browser using python?

like image 455
nomisk Avatar asked Mar 31 '18 13:03

nomisk


People also ask

Is it possible to run a Selenium test without using a real browser?

We can perform Selenium testing without a browser. This is achieved by triggering the execution in a headless mode. The headless execution can decrease the utilization of key resources and is being adopted widely.

Can Selenium be used for mobile browser testing?

Yes. Selenium is used to automate web browsers. It is primarily used for cross-browser testing of web applications. Appium, on the other hand, is mainly used for automating tests for native, hybrid, and mobile web apps on mobile devices.

Can I use Selenium without GUI?

We can run Selenium (Firefox) webdriver without a GUI. This means that the execution has to be kicked in headless mode. The headless execution is popular now since it results in less consumption of resources. Firefox, without GUI, can be executed after we set the geckodriver path.


1 Answers

Passing correct user agent should do the trick. Example with mobile Chrome:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument('--user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1')
driver = webdriver.Chrome(options=chrome_options)
driver.get('https://www.google.com')
like image 84
hoefling Avatar answered Sep 27 '22 20:09

hoefling