2

I'm aware this question has been asked before, the issue is that none of the solutions do the job quite the same as the Developer tools extension which is what I'm in need of. This is achieved by going into the WebDeveloper extension menu and clicking 'Disable all styling' in the css section.

I need the page to look like this for some automation.

Needed Format (No CSS styling at all)

The first solution is

from selenium.webdriver.firefox.firefox_profile import FirefoxProfile

def disableImages(self):
## get the Firefox profile object
firefoxProfile = FirefoxProfile()
## Disable CSS
firefoxProfile.set_preference('permissions.default.stylesheet', 2)
## Disable images
firefoxProfile.set_preference('permissions.default.image', 2)
## Disable Flash
firefoxProfile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so',
                              'false')
## Set the modified profile while creating the browser object 
self.browserHandle = webdriver.Firefox(firefoxProfile)

However, this only removes some images and not everything as you can see below.

1st Solution

Then I found a script

var queries = ['link[rel=stylesheet][href]', 'style'];
for (var i = 0; i < queries.length; i++) {
    var remove = document.querySelectorAll(queries[i]);
    for (var j = 0; j < remove.length; j++) {
        remove[j].outerHTML = '';
    }
}
var inline = document.querySelectorAll('*[style]');
for (var i = 0; i < inline.length; i++) {
    inline[i].removeAttribute('style');
}

The full explanation of how it worked is on this answer Disable styling on Google Search with Selenium FirefoxDriver which still did not turn out the same.

2nd Solution

Any help would be greatly appreciated? Thanks in advance.

RemakingEden
  • 257
  • 3
  • 11

1 Answers1

0

Seems you were pretty close.

I have added two additional preferences in addition to the set you have used and I am able to achieve the desired results i.e. get rid of all the CSS Styling within Firefox.

  • Code Block:

    from selenium import webdriver
    
    firefoxProfile = webdriver.FirefoxProfile()
    firefoxProfile.set_preference('permissions.default.stylesheet', 2)
    firefoxProfile.set_preference('permissions.default.image', 2)
    firefoxProfile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so', 'false')
    firefoxProfile.set_preference("permissions.default.script", 2);
    firefoxProfile.set_preference("javascript.enabled", False);
    browserHandle = webdriver.Firefox(firefox_profile=firefoxProfile, executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
    browserHandle.get('https://play.google.com/store')
    
  • Browser Snapshot:

play_google_com_store

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks for the advice. For some reason on https://play.google.com/apps/publish/signup/ I get inconsistent behavior with this. Mainly still looking like the normal page. Without a Google Play account it may be a little hard to test unfortunately. – RemakingEden Nov 23 '18 at 12:39
  • @JossSparkes It is not an **advice** as such but a **well researched, canonical answer**. If you have counter question feel free to ask me here. – undetected Selenium Nov 23 '18 at 12:41
  • 1
    Okay, thanks for the well researched, canonical answer . My question is, the above code works on https://play.google.com/store however it does not appear to work on https://play.google.com/apps/publish/signup/. Do you know the reason for that? – RemakingEden Nov 23 '18 at 12:54
  • @JossSparkes Both your screenshots refer to `https://play.google.com/store`. So was my answer. If your requirement have changed. Feel free to raise a new question with your new requirement. Stackoverflow contributors will be happy to help you out. – undetected Selenium Nov 23 '18 at 12:59
  • 1
    All 3 of my screenshots point to play.google.com/apps/publish and some extra I have cut off for privacy these url's resolve to https://play.google.com/apps/publish/signup/ if you have not yet signed in. As I presumed you may not have a Google Developer account to hand I asked about the page it would resolve to for you. I will keep the current question up for now. – RemakingEden Nov 23 '18 at 13:09