How to Switch from Mobile Sites to Desktop Sites in Chrome?

Hello everyone, I’m Darshan Hiranandani, need help with switching from mobile sites to desktop versions in Chrome. I’ve already tried a few methods like adjusting the viewport, using JavaScript to change the user agent, and appending “?view=desktop” to the URL, but nothing seems to work. I’d like to find a solution without clicking specific elements or using tricks like that. Is there any way to adjust settings directly through ‘chrome://settings’ or another method you suggest? Please share your thoughts and suggestions! Thank you!

Regards
Darshan Hiranandani

1 Like

What do you mean by the words: “mobile site” and “desktop version”? Please elaborate them, as I have no idea what.

Hi @darshanhiranandani23,

Welcome to our community. Thank you for sharing your issue.

Doing some research, I recommend that:
You can automate the process of switching between mobile and desktop views using KS as follows:

  1. Change the User-Agent Using Katalon
    You can set a custom user-agent to mimic a desktop browser when making requests or opening web pages. Example:
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions

// Set up ChromeOptions with a desktop user-agent
ChromeOptions options = new ChromeOptions()
options.addArguments("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36")

// Start WebDriver with the options
WebDriver driver = new ChromeDriver(options)

// Open the desired URL in desktop view
driver.get('https://example.com')

// Use Katalon WebDriver to interact
WebUI.openBrowser('')
WebUI.switchToWindowIndex(0)

This will force the browser to load the desktop version by changing the user-agent.

  1. Set Viewport to Desktop Dimensions
    If the website is relying on screen dimensions instead of user-agent detection, adjust the browser window size to mimic a desktop environment using setViewPortSize()
    This approach ensures the browser renders the desktop version based on screen dimensions.

  2. Append Query Parameters in Tests
    Some websites use query parameters like ?view=desktop to switch views, using WebUI.navigateToUrl(url + '?view=desktop')

  3. Verify Desktop View
    You can verify whether the view is correct by checking specific elements unique to the desktop layout:

boolean isDesktopView = WebUI.verifyElementPresent(findTestObject('Page_DesktopSpecificElement'), 5)
if (isDesktopView) {
    println 'Desktop view successfully loaded!'
} else {
    println 'Failed to load desktop view.'
}

Hope this can help you. Let us know your trial

did it work @darshanhiranandani23