Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to open firefox in mobile mode with desired viewport #817

Closed
dilpreetbadwal opened this issue Jul 10, 2017 · 3 comments
Closed

Unable to open firefox in mobile mode with desired viewport #817

dilpreetbadwal opened this issue Jul 10, 2017 · 3 comments

Comments

@dilpreetbadwal
Copy link

In order to help us efficiently investigate your issue, please provide the following information:

Platform and application details

  • Platform:
  • Firefox:
  • Selenium: <3.3.1>

I have written the code below to open firefox in responsive mode . . The firefox opens in mobile mode but with default size and not the size mentioned in code.

Please check and let me know the issue

public class FirefoxResponsiveMode {

    public static void pressShortcut(WebDriver driver) throws AWTException {
    Robot robot = new Robot();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_M);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.keyRelease(KeyEvent.VK_M);
    //WebElement e= driver.findElement(By.xpath("html/body"));
    //e.sendKeys(Keys.chord(Keys.CONTROL,Keys.SHIFT));
       // Actions actions = new Actions(driver);
       // actions.keyDown(Keys.CONTROL).keyDown(Keys.SHIFT).sendKeys("m").keyUp(Keys.SHIFT).keyUp(Keys.CONTROL).perform();
    }

    public static void setViewSize(FirefoxProfile profile, String viewDeviceName, Integer width, Integer height) throws InterruptedException {
    Thread.sleep(3000);
      //  String responsiveMode = "[{"width": " + width + ", "name": "" + viewDeviceName + "", "key": "" + width + "x" + height + "", "height": "
         //       + height + "}]";
    String responsiveMode =
                "[{"width": " + width + ", "name": "" + viewDeviceName + "", "key": "" + width + "x" + height + "", "height": "
    + height + "}]";
   

        profile.setPreference("devtools.responsiveUI.presets", responsiveMode);
        Thread.sleep(3000);
    }
}

package test;

import java.awt.AWTException;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.remote.DesiredCapabilities;

public class MT {

public static void main(String[] args) throws InterruptedException, AWTException {
	System.setProperty("webdriver.gecko.driver", "C:\\Users\\pawan\\Desktop\\geckodriver.exe");
	FirefoxProfile profile = new FirefoxProfile();
	FirefoxResponsiveMode.setViewSize(profile, "Phones", 60, 600);
	DesiredCapabilities cap = DesiredCapabilities.firefox();
	cap.setCapability(FirefoxDriver.PROFILE, profile);
	WebDriver DRIVER = new FirefoxDriver(cap);
	//DRIVER.manage().window().maximize();
	DRIVER.navigate().to("http://rediff.com");
	FirefoxResponsiveMode.pressShortcut(DRIVER);
	//FirefoxResponsiveMode.setViewSize(profile, "mobile", 260, 600);

}
@andreastt
Copy link
Contributor

Without knowing what FirefoxResponseMode is, I can’t tell what’s wrong. There is not enough information in this bug that it is actionable.

@whimboo
Copy link
Collaborator

whimboo commented Jul 17, 2017

You are trying to use features which are only available in chrome scope of Firefox. While staying in content (which is the default) you won't be able to open the responsive design mode of Firefox. So switch the context to chrome first, and then try again. Whereby you will have to check if your Selenium binding is supporting that already or not. For the Python binding it would be driver.set_context("chrome").

I'm keeping this issue closed given the above clarification.

@lock
Copy link

lock bot commented Aug 17, 2019

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have run into an issue you think is related, please open a new issue.

@lock lock bot locked and limited conversation to collaborators Aug 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants