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>
Related
Im trying to make a bot that visits my adfly link using the chrome webdriver. Every time I try to use the code below though, the webdriver tells me that there were too many redirects and doesn't follow through. The code below is just being used for testing at the moment:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("--proxy-server="+"http://102.129.249.120:8080")
browser = webdriver.Chrome(options=options)
browser.get("http://raboninco.com/18Whc")
Image of error here
Okay so i figured it out. I can use tor with selenium to get access to adfly. Works great btw. Thanks for the help and time guys. If you want to see the code I used, here it is:
from selenium import webdriver
import os
os.popen(r'C:\Users\joldb\Desktop\Tor Browser\Browser\TorBrowser\Tor\tor.exe')
options = webdriver.ChromeOptions()
options.add_argument("--proxy-server="+"socks5://127.0.0.1:9050")
browser = webdriver.Chrome(options=options)
browser.get("http://raboninco.com/18Whc")
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
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
I'm trying to start a full screen page in Firefox with Selenium in Python 3. The page opening works fine, but when I send the F11 key to the browser (the Full Screen key), anything happens. Here is my code :
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
firefox = webdriver.Firefox()
firefox.get('http://localhost')
firefox.maximize_window()
body = firefox.find_element_by_tag_name('html')
body.send_keys(Keys.F11)
Does anyone know how to make my page start in full screen ? I know it's possible with Chrome, but it's harder with Firefox
This is what worked for me.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get('http://localhost')
driver.find_element_by_xpath('/html/body').send_keys(Keys.F11)
Hope this helps
Just realized I am using Python 2.6 vs your 3. Sorry about that, but at least you know it will work on an older Python version
Selenium has a built-in method to make the window fullscreen: fullscreen_window()
Selenium API - fullscreen_window()
Invokes the window manager-specific ‘full screen’ operation
browser.get("https://www.screenku.com")
browser.fullscreen_window()
pip3 install selenium pyautogui
#!/usr/bin/env python3
import pyautogui
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference("dom.webnotifications.enabled", False)
profile.set_preference("general.useragent.override", "Mozilla/5.0")
profile.update_preferences()
browser = webdriver.Firefox(firefox_profile=profile,executable_path = '/usr/local/bin/geckodriver')
browser.get("https://www.screenku.com")
pyautogui.press('f11')
I want to run tests with selenium. IE gives me a modal error after bringing up IE 8 with this text "This is the initial start page for the WebDriver server" :
from selenium import webdriver
import time
browser = webdriver.Ie() # Get local session of IE
browser.get("http://www.google.com") # Load page
time.sleep(5)
browser.close()
So I tried Chrome.
from selenium import webdriver
browser = webdriver.Chrome()
browser.get("http://www.google.com")
time.sleep(5)
browser.close()
and Selenium errors for not having the right path to the chrome.exe application. Chrome is installed as expected... C:\Users\%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe
A little help here would be greatly appreciated.
Have u downloaded the Chrome Driver?
To get set up, first download the appropriate prebuilt server. Make sure the server can be located on your PATH or specify its location via the webdriver.chrome.driver system property.
Then when u run
from selenium import webdriver
browser = webdriver.Chrome()
browser.get("http://www.google.com")
time.sleep(5)
browser.close()
It should work.