Open chrome in mobile emulation mode

673 views
Skip to first unread message

greenOnliner

unread,
May 31, 2016, 6:43:15 AM5/31/16
to Selenium Users
Hi,

I am new to selenium (coding in python) and I would like to open chrome in mobile emulation mode but can't find a code that does that.

Thanks,

Andrew Jervis

unread,
Jun 1, 2016, 11:54:52 AM6/1/16
to Selenium Users
I dont fully understand the term 'mobile emulation code'. However, the following opens Chrome as a Browser which may help

1. Download the latest Chrome driver installable from http://chromedriver.storage.googleapis.com/index.html

2. Unzip the file and run the Chromedriver.exe file. This should start the Chromedriver on port 9515

3. Install the Chrome Browser

4. In Selenium webdriver create a Class file and use the following code (adjust the location of the Chrome driver as appropriate

package Trainingpack;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class chrome1 {
   
    public static void main(String[] args) throws Exception {

    System.setProperty("webdriver.chrome.driver","c:\\ca\\chromedriver.exe");
       
    WebDriver driver = new ChromeDriver();
   
    driver.get("http://www.google.com");
   
    WebElement searchBox = driver.findElement(By.name("q"));
   
    searchBox.sendKeys(new String[] {"Chrome Driver"});
       
    }

}

Hope that helps




 

⇜Krishnan Mahadevan⇝

unread,
Jun 2, 2016, 7:04:59 AM6/2/16
to Selenium Users
@Andrew

Mobile emulation mode is something that chrome supports. It basically lets the user alter the userAgent (This is how all web servers identify as to what browser flavor+OS combination is the user using and then serve pages accordingly) and lets users view their web page on a mobile device for e.g., from within their desktop browser itself.

@GreenOnliner


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/9218c6a5-575c-4d16-b76b-3a3aa73bb7a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ravi Kumar

unread,
Jun 5, 2016, 2:22:01 AM6/5/16
to Selenium Users
Reply all
Reply to author
Forward
0 new messages