I'm trying to teach myself some python and I've been working on a project which uses selenium to open firefox and interact with netflix but I need to enable 'Play DRM' to stream, I dont see it in 'set_preferences' and I cant inspect element on the contents page in preferences so I'm not sure how to enable it.
import time, pyautogui, os
from selenium import webdriver as wd
from selenium.webdriver.common.keys import Keys
profile = wd.FirefoxProfile()
ntfx='http://www.netflix.com/'
driver=wd.Firefox()
driver.get(ntfx)
url = driver.current_url
Took 4 days but finally came with a solution
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.addPreference("media.eme.enabled",true);
firefoxOptions.addPreference("media.gmp-manager.updateEnabled", true);
Then add the firefoxOptions to the driver
Ok looked more into the Firefox Profiles and made a custom profile as show here. I went into preferences/content and enabled "Play DRM" and added the PATH to the custom profile
profile = wd.FirefoxProfile('./fire_fox_profile')
driver=wd.Firefox(profile)
As alternative solution of using firefox profiles you can do
driver.get('about:preferences')
driver.find_element_by_id('playDRMContent').click()
The method of #RonanB worked for me
Just go into about:profiles in firefox
then under the DRM enabled profile, look for the root directory. For me it was : /home/myusername/.mozilla/firefox/14iw27z4.default-release
so like this :
myProfile = webdriver.FirefoxProfile('/home/myusername/.mozilla/firefox/14iw27z4.default-release')
driver = webdriver.Firefox(myProfile)
First time answering any question on stackoverflow
This little trick worked for me so what i did was
First make sure normal firefox(i.e when not launched using selenium or firefox) is able to play drm video.
Next, i created new firefox profile named 'selenium' and launched firefox with selenium profile.
To create firefox profile run 'firefox -p' command in windows run program. picture for ref
Now in 'selenium' profile firefox session go to drm video site. Firefox downloaded some drm playing content and after some time drm video played.
then i launched firefox with this code:-
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
profile = webdriver.FirefoxProfile(r"C:\Users{USER}----PATH TO SELENIUM PROFILE FOLDER----")
print('lll')
driver = webdriver.Firefox(profile, executable_path=r'-------------\firefox\geckodriver.exe')
url = 'http://amp.azure.net/libs/amp/latest/samples/videotag_multiDRM_PlayReadyWidevineFairPlay_notoken.html'
driver.get(url)
and my drm video played,
Now this worked for me not sure will work for you
tested on:-
Firefox Version 92.0(64-bit)
gechodriver version geckodriver-v0.29.1-win64
Related
When I run this code, the page opens and closes. I can't reach the page. Everything is in the latest version. I am a Windows user.
I was trying to open Instagram page with this code.
enter image description here
I tried to open the instagram site with this code and the site was closed as soon as it was opened.
Im not familiar with selenium but I know for a fact that
get() just gets the HTML code of the website and does not display it
You have to add the below Chrome Option:
options.add_experimental_option("detach", True)
Full code:
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=Service(chrom_driver_pat), options=options)
driver.get(<url>)
Next time, don't post the image, post the code and explain your issue clearly.
First of all, please, do not use images when your want a code review or help, it is more easier to help with raw code.
Selenium now uses Service method to run webdriver.
To run what you want, you need to fix some parts of your code, like this:
from selenium import webdriver
# in my case, i'm using selenium==4.5.0, for this version, is necessary to
# use selenium.webdriver.chrome.service to use driver path
from selenium.webdriver.chrome.service import Service as ChromeService
# For Windows path, use r"C:\..." when you will use \
# Remember to set the executable file too
chrome_driver_path = r"C:\pythondriver\chromedriver\chromedriver.exe"
# you can use "universal" path too, like linux, using / instead of \
# chrome_driver_path = "C:/pythondriver/chromedriver/chromedriver.exe"
# instead using:
# webdriver.Chrome()
# driver = webdriver.Chrome(chrome_driver_path)
# use this:
chrome_service = ChromeService(chrome_driver_path)
driver = webdriver.Chrome(service=chrome_service)
url = "https://instagram.com"
driver.get(url)
I tested using the configurations below and worked for me:
Chromedriver - 108.0.5359.71
Chrome - 108.0.5359.125 - 64 bits
If you need more help using Chrome Service, try look the Selenium Docs
I'm trying to clear the cache from the chrome driver with selenium.
The below code worked fine for a day, and now it has stopped working for some reason. It redirects to the ClearBrowserData url, but it does not press enter to run the Clear Data button.
Am I doing something wrong? I would appreciate some help on this.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
chromedriver = 'path'
browser = webdriver.Chrome(executable_path = chromedriver)
browser.get('chrome://settings/clearBrowserData')
browser.find_element_by_xpath('//settings-ui').send_keys(Keys.ENTER)
beacuse shadowRoot
<settings-clear-browsing-data-dialog>
#shadow-root (open)
</settings-clear-browsing-data-dialog>
In order to perform the testing I have to open the Chromium Browser. But When i use
driver = webdriver.Edge('msedgedriver.exe')
driver.get('https://xxx.service-now.com/')
it is taking me to the sign-in page.
But when i normally open 'xxx.service-now.com' it takes windows authentication and takes me to the service-now page directly.
This is my normal Chromium Window
and this is my Chromium Window when i am opening using Selenium
I want to open the normal Chromium using selenium, as it will automatically sign me in.
Your help will be appreciated.
After doing some experiments i got the answer.
import selenium, getpass
from selenium import webdriver
from msedge.selenium_tools import Edge, EdgeOptions
user = getpass.getuser()
options = EdgeOptions()
options.use_chromium = True
options.add_argument("user-data-dir=C:\\Users\\" + user + "\\AppData\\Local\\Microsoft\\Edge\\User Data")
driver = Edge('msedgedriver.exe',options = options)
driver.get('https://xxx.service-now.com/')
This has resolved my issue.
I am on Mac OS X using selenium with python 3.6.3. Im using this code, but browser Google chrome closes immediately after being launched with selenium I start this code, Google chrome opens new windows with Default profile, but chrome wont open the url google.com.
Whats problem with code? Thanks for the help!
FILE_NAME_PROFILE = '/Users/User/Library/Application Support/Google/Chrome'
options = webdriver.ChromeOptions()
options.add_argument('--user-data-dir='+FILE_NAME_PROFILE)
driver = webdriver.Chrome('assets/chromedriver', chrome_options=options)
driver.get("https://google.com")
I am using two arguments and work well in development
"user-data-dir=C:\Users\NameUser\AppData\Local\Google\Chrome\User Data"
"profile-directory=Default"
If you want use another profile (not default) you have to create it and only you have to change the second argument. All profiles are stored in 'User Data' folder
"profile-directory=Profile 1"
I'd like to ask something about Selenium library in Python.
I'm trying to open a webpage, directly log onto it, and access another webpage behind it (I wanted to navigate on the website after the login) with a Python script. I've found the following code on the Internet but I have a problem with the line:
browser = webdriver.Firefox()
It just opens a blank page in Firefox and it looks like the script get stuck with it and does nothing afterwards. I tried in the Python interpreter and it's the same, it opens a blank page in Firefox and I lose the hand (I can't enter other commands).
python interpreter blocked:
I'm using Selenium-3.3.1 and I work under CentOS 6.5.
Is it normal? Am I missing something obvious?
Here is my code:
#!usr/bash/python
from selenium import webdriver
from selenium.webdriver.support import ui
from selenium.webdriver.common.keys import Keys
def loadedPage(browser):
return browser.find_element_by_tag_name("body") != None
browser = webdriver.Firefox() #supposedly just a firefox webdrive instance creation
browser.get("http://machine/machineDir/index.php")
wait = ui.WebDriverWait(browser, 10)
wait.until(loadedPage)
username=browser.find_element_by_id("username")
username.send_keys("userTest")
passwd=browser.find_element_by_id("password")
passwd.send_keys("userTestpass")
passwd.send_keys(Keys.RETURN)
As you are using selenium 3, firefox browser can't be instantiate directly, you need to configure gecko driver for the same.
System.setProperty("webdriver.gecko.driver","path of geckodriver.exe");
I fixed it using the right version of Selenium for my old Firefox.
Firefox version: 17.0.10
Selenium version installed: 2.40