I want to create a fake webcam stream for Firefox. At the moment I have the desired capability media.navigator.streams.fake but I'm not sure how to get a specific video file to play.
How can I do this?
For Firefox you can use the following code in Python:
from selenium import webdriver
options = webdriver.FirefoxOptions()
options.set_preference("media.navigator.streams.fake", True)
driver = webdriver.Firefox(firefox_options = options)
Or if you are using desired capabilities with other options then it will be like:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
options = webdriver.FirefoxOptions()
options.set_preference("media.navigator.streams.fake", True)
desired = DesiredCapabilities.FIREFOX
desired.update(options.to_capabilities())
driver = webdriver.Firefox(desired_capabilities=desired)
PS: You can translate it into any needed programming language.
According to your question: Firefox does not support specific video file to play inside the fake webcam -- https://github.com/mozilla/geckodriver/issues/1429.
Hope it helps you!
An alternative would be that you use User Agent in chrome and then injecting the video file:
ChromeOptions options = new ChromeOptions();
options.addArguments("--use-fake-ui-for-media-stream");
options.addArguments("--use-fake-device-for-media-stream");
options.addArguments("--use-file-for-fake-video-capture=path/to/video.y4m");
options.addArguments("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0");
webDriver = new ChromeDriver(options)
PS: I create the issue that Ratmir Asanov commented
github.com/mozilla/geckodriver/issues/1429
If you want to play a specific file with firefox, I think you will have to simulate a webcam on your instance (with v4l2loopback for example), and then play your file on the virtual webcam with smthing like ffmpeg.
With selenium, you will also have to update your firefox profile for allowing access to your fake webcam.
Related
I am using Linux Mint 20. I am using User-Agent Switcher and Manager and Spoof Timezone with firefox. I want to load the current firefox user profile and use Chrome 99.0.7113.93 (Windows) user agent using selenium. In addition to that, when right click on Spoof Timezone, there is an option Update timezone from IP, I also want to click that before going through rest of the process.
Currently I am following save document.cookie output in a file and came up to:
driver = webdriver.Firefox(
executable_path=GeckoDriverManager(cache_valid_range=1).install())
driver.get('https://www.skillshare.com/')
cookie = driver.execute_script('return document.cookie')
f = open("/home/blueray/Desktop/cookie.txt", "w")
f.write(cookie)
f.close()
driver.close()
How can I do that?
Unfortunately you cant exactly click on the on the extensions with selenium, since they are not part of the page DOM.
For User-Agent Switcher and Manager you can just inject the user agent without using the extension
For Spoof Timezone, You can access the about:addons, click on the extension, preferences, check the automatically update timezone based on my IP address and click save. Cant do it with selenium since that part is under a shadowroot that doesnt display these settings. Hopefully when the selenium launches you will have the setting already saved, after you've done this step manually.
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
options = webdriver.FirefoxOptions()
# Define and set the user agent to Chrome 99;
# The User-Agent Switcher and Manager extension has no config page that we can access as an url and click on it with selenium;
# Therefore we can injecting the user agent instead
user_agent = "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.7113.93 Safari/537.36"
options.set_preference("general.useragent.override", user_agent)
# load the firefox profile
# to get this: open in firefox the url about:profiles and its the Profile: default-release => Root Directory
firefox_profile = FirefoxProfile('/home/art/.mozilla/firefox/kd5i4tgp.default-release')
options.profile= firefox_profile
firefox_profile.add_extension("/home/art/.mozilla/firefox/kd5i4tgp.default-release/extensions/{55f61747-c3d3-4425-97f9-dfc19a0be23c}.xpi") # for spoof timezone
#download from here https://github.com/mozilla/geckodriver/releases/tag/v0.29.1 linux64.tar.gz, I've put mine in Documents
driver = webdriver.Firefox(options=options,executable_path="/home/art/Documents/geckodriver")
driver.get('https://www.skillshare.com/')
cookie = driver.execute_script('return document.cookie')
f = open("/home/blueray/Desktop/cookie.txt", "w")
f.write(cookie)
f.close()
driver.close()
I am attempting to load a chrome browser with selenium using my existing account and settings from my profile.
I can get this working using ChromeOptions to set the userdatadir and profile directory. This loads the browser with my profile like i want, but the browser then hangs for 60 seconds and times out without advancing through any more of the automation.
If I don't use the user data dir and profile settings, it works fine but doesn't use my profile.
The reading I've done points to not being able to have more than one browser open at a time with the same profile so I made sure nothing was open while I ran the program. It still hangs for 60 seconds even without another browser open.
m_Options = new ChromeOptions();
m_Options.AddArgument("--user-data-dir=C:/Users/Me/AppData/Local/Google/Chrome/User Data");
m_Options.AddArgument("--profile-directory=Default");
m_Options.AddArgument("--disable-extensions");
m_Driver = new ChromeDriver(#"pathtoexe", m_Options);
m_Driver.Navigate().GoToUrl("somesite");
It always hangs on the GoToUrl. I'm not sure what else to try.
As per your code trials you were trying to load the Default Chrome Profile which will be against all the best practices as the Default Chrome Profile may contain either of the following:
Extensions
Bookmarks
Browsing History
etc
So the Default Chrome Profile may not be in compliance with you Test Specification and may raise exception while loading. Hence you should always use a customized Chrome Profile as below.
To create and open a new Chrome Profile you need to follow the following steps :
Open Chrome browser, click on the Side Menu and click on Settings on which the url chrome://settings/ opens up.
In People section, click on Manage other people on which a popup comes up.
Click on ADD PERSON, provide the person name, select an icon, keep the item Create a desktop shortcut for this user checked and click on ADD button.
Your new profile gets created.
Snapshot of a new profile SeLeNiUm
Now a desktop icon will be created as SeLeNiUm - Chrome
From the properties of the desktop icon SeLeNiUm - Chrome get the name of the profile directory. e.g. --profile-directory="Profile 2"
Get the absolute path of the profile-directory in your system as follows :
C:\\Users\\Thranor\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2
Now pass the value of profile-directory through an instance of ChromeOptions with AddArgument method along with key user-data-dir as follows :
m_Options = new ChromeOptions();
m_Options.AddArgument("--user-data-dir=C:/Users/Me/AppData/Local/Google/Chrome/User Data/Profile 2");
m_Options.AddArgument("--disable-extensions");
m_Driver = new ChromeDriver(#"pathtoexe", m_Options);
m_Driver.Navigate().GoToUrl("somesite");
Execute your Test
Observe Chrome gets initialized with the Chrome Profile as SeLeNiUm
If you want to run Chrome using your default profile (cause you need a extension), you need to run your script using another browser, like Microsoft Edge or Microsoft IE and your code will lunch a Chrome instance.
My Code in PHP:
namespace Facebook\WebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Chrome\ChromeOptions;
require_once('vendor/autoload.php');
$host = 'http://localhost:4444/';
$options = new ChromeOptions();
$options->addArguments(array(
'--user-data-dir=C:\Users\paulo\AppData\Local\Google\Chrome\User Data',
'--profile-directory=Default',
'--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'
));
$caps = DesiredCapabilities::chrome();
$caps->setCapability(ChromeOptions::CAPABILITY, $options);
$caps->setPlatform("Windows");
$driver = RemoteWebDriver::create($host, $caps);
$driver ->manage()->window()->maximize();
$driver->get('https://www.google.com/');
// your code goes here.
$driver->quit();
i guys, in my enviroment with chrome 63 and selenum for control, i have find same problem (60 second on wait for open webpage).
To fix i have find a way by setting a default webpage in chrome ./[user-data-dir]/[Profile]/Preferences file, this is a json data need to insert in "Preferences" file for obtain result
...
"session":{
"restore_on_startup":4,
"startup_urls":[
"http://localhost/test1"
]
}
...
For set "Preferences" from selenium i have use this sample code
ChromeOptions chromeOptions = new ChromeOptions();
//set my user data dir
chromeOptions.addArguments("--user-data-dir=/usr/chromeDataDir/");
//start create data structure to for insert json in "Preferences" file
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("session.restore_on_startup", 4);
List<String> urlList = new ArrayList<String>();
urlList.add("http://localhost/test1");
prefs.put("session.startup_urls", urlList);
//set in chromeOptions data structure
chromeOptions.setExperimentalOption("prefs", prefs);
//start chrome
ChromeDriver chromeDriver = new ChromeDriver(chromeOptions);
//this get command for open web page, response instant
chromeDriver.get("http://localhost/test2")
i have find information here https://chromedriver.chromium.org/capabilities
I am trying to login to my e-trade account via selenium and/or chrome_driver, but each time I attempt to login e-trade seems to be able to detect that I am using a webdriver and block the login. Is there any way for me to point my chrome driver to my normal chrome session? or prevent etrade from detecting that I am using one of these drivers? I have read a few other SO posts that have suggested some workarounds, but so far nothing has worked. I have tried both webdrivers on chrome and firefox, also tried clearing my cookies before login.
I am on ChromeDriver 76.0.3809.126 and Selenium server version: 3.141.59, any suggestions to get around this would be greatly appreciated.
I use python asyncio and pyppeteer with chrome to automate the login into etrade. A few months ago etrade changed something and I started getting blocked. With headless set to False I could see an error warning that stated to call etrade with the IP address. After a long back and forth they sent me a set of cookies (see below) that needed to be passed with a customer value specific to my account. Once they gave me the ETWLCUST1 value for the value key everything was golden from there on out. This isn't documented on the site so it was painful to figure out, but it worked for me. This may be what is blocking your access. I also passed user-agents prior to whatever etrade changed, and I still do, so that wasn't the issue for me.
Good luck if it works!
cookies = {'name':'SWH','value':'ETWLCUST1-xxxxxxx-xxxx','domain':'.etrade.com','secure':True,'httpOnly':True}
To achieve this you need to use the chrome User-Agent command-line option:
As you have not mentioned which language you are using, I am writing code in Java and Python.
To achieve this you need to use the chrome user-agent command line option.
JAVA:
ChromeOptions options = new ChromeOptions();
options.addArguments("--user-agent="+ PUT_USER_AGENT_HERE);
WebDriver driver = new ChromeDriver(options);
PYTHON:
opts = Options()
opts.add_argument("user-agent=PUT_USER_AGENT_HERE")
driver = webdriver.Chrome(chrome_options=opts)
How to get the User-Agent:
Open your actual browser.
Right-click and open inspect element.
Now go to console.
Now copy-paste below code.
Code:
navigator.userAgent
Example: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36
According to this Google does not support logging in with automation testing frameworks. I am trying to populate a calendar with game release data I scraped from here to make a public calendar I can share on reddit. I have scraped the data but now i can't even log into Google on the webdriver. What are the solutions to this?
driver = webdriver.Chrome()
driver.get("https://calendar.google.com/calendar/r")
pdb.set_trace()
#manual log in gives error
Error message: You are trying to sign in from a browser or app that doesn't allow us to keep your account secure.
Try using a different browser Learn More
There is some hack or workaround for this by setting the User-Agent in Chrome.
To achieve this you need to use the chrome user-agent command line option.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
opts = Options()
opts.add_argument("user-agent=PUT_USER_AGENT_HERE")
driver = webdriver.Chrome(chrome_options=opts)
driver.get("https://calendar.google.com/calendar/r")
pdb.set_trace()
#manual log in gives error
How to get the User-Agent:
Open your actual browser.
Right-click and open inspect element.
Now go to console.
Now copy-paste below code.
Code:
navigator.userAgent
Example: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36
I'm trying to automate a secure application(with useragent - iphone) which asks for authentication when i open the site. I tried giving the credentials in the URL itself to bypass the authentication but it pops up a dialogbox for confirmation which i'm unable to handle it through code.
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("general.useragent.override",
"Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1"
+ "(KHTML, like Gecko) Version/3.0 Mobile/3B48b Safari/419.3)");
WebDriver driver = new FirefoxDriver(profile);
String site = "http://akamai:ecnt0k3n#ecn13-secure-store.nike.com";
driver.get(site);
Any help on this is highly appreciated.
Thanks,
Bhavana
Mozilla blocks fishing attempts. Did you check Network.http.phishy-userpass-length?
By the way, according to Selenium's issue 34#8, this should work:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.http.phishy-userpass-length", 255);
driver = new FirefoxDriver(profile);
driver.get("http://username:password#www.basicauthprotected.com/");
Note: this question is almost the same as BASIC Authentication in Selenium 2 - set up for FirefoxDriver, ChromeDriver and IEdriver.
You can use Selenium's new WebDriver to enter information into a dialog box of that type. However I haven't done it.