I want Selenium to open and control one of my existing Chrome profile named Selenium. I've tried different solutions but none of them work.
Profile name : Selenium
Profile directory : Profile 5
1- First I've tried :
options = webdriver.ChromeOptions()
options.add_argument('user-data-dir=C:/Users/raphg/AppData/Local/Google/Chrome/User Data')
options.add_argument('profile-directory=Profile 5')
This opens the right chrome profile but in a Chrome window that is not controlled by Selenium. Plus, my script crashes with the error : selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument
2- Then I've tried to clone the profile directory and to reference it like this :
options = webdriver.ChromeOptions()
options.add_argument('user-data-dir=C:/Users/path_where_I_put_the_directory')
options.add_argument('profile-directory=Profile 5')
This time, it gives me no crashes, but this opens a Chrome profile that is like a clone of my Selenium profile and it is not connected to my Google account unlike the real one.
With images, real profile VS the clone :
Solved!
In short: you need to clone the entire 'User Data' folder, not just the profile you'll be using.
Here were the problems:
For the first solution I've tried, the error I got (user data directory is already in use) speaks for itself, I couldn't use any profiles if I had already a profil in use. Here I was using 'Default' (for browsing purpose) so using any profile in User Data folder with Selenium would give this error.
That brings us to the second solution I've tried : moving the profile I needed to another location. The reason Selenium webdriver opened like a clone of my profile was because it was missing some files from the 'User Data' folder.
So to solve this:
1- Go to C:\Users\name\AppData\Local\Google\Chrome and copy the 'User Data' folder
2- Paste it to wherever you want (let's say to C:/Users/my_scripts. So now you have C:/Users/my_scripts/User Data)
3- Use the profile you want with Selenium
options = webdriver.ChromeOptions()
options.add_argument('user-data-dir=C:/Users/my_scripts/User Data')
options.add_argument('profile-directory=Default')
# Or
options.add_argument('profile-directory=Profile 5')
Related
I'm currently working with 2 monitors, and I've noticed that Robot Framework (using SeleniumLibrary) always open the test execution in the main display that is selected in windows display settings.
Is there any way to choose which monitor will be used to display test execution?
This is how I'm starting the browser. I'm currently using Chrome
Start Browser
Open Browser ${url} ${BROWSER}
... options=add_experimental_option("excludeSwitches", ["enable-logging"])
Maximize Browser Window
Ragnoroct's answer here seems to be a solution: https://stackoverflow.com/a/57545639/16635196.
Chrome has a command-line switch for window position
--window-position=x,y
https://peter.sh/experiments/chromium-command-line-switches/#window-position
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('window-position=2000,0') # opens at x=2000,y=0 from the start
driver = webdriver.Chrome(options=options)
Since I was not using Python directly in the Robot tests, I resorted to directly modifying the Python package source where these options are set. For example, AppData\Local\Programs\Python\Python310\lib\site-packages\QWeb\internal\browser\chrome.py for combination of QWeb and Windows10. Obviously not a good way of doing things in the long run, but virtual environment could be of help here.
Start-maximized didn't work in conjunction with window-position, so I had to additionally use window-size=2560,1440.
I want to upload a file to automate a process with Selenium IDE from chrome, I already gave the permissions to the extension, however I get the following error yet.
The way I'm loading the file is as follows:
Command: type
id= txtFile
Value: C:\fakepath\factura.xls
Failed:
Unable to upload files due to cross origin frames in the page
https://i.stack.imgur.com/LNUqH.png
ist because of the Fakepath
You need to insert the direct path.
You can look it up by making a left click in the Explorer on the document.
The path should be visible now
Here, it is possible to set the default download directory using preferences in chrome_capability during the driver initialization.
But, is it possible to modify the chrome preferences during the test?
In my scenario, I need to download a particular file in a specific directory, in order to access the file(since the filename is randomly generated) so that i can keep the 'specific directory' clean and get the file name(since there will be only one file)
I searched a bit and lots of people said that Driver options have to be declared before driver initialization so it is not possible to change download directory after you initialized driver object. You need to open new driver and set its options while your test in execution.
I am running Jmeter with the Webdriver plugin installed on Windows 7. My current test plan contains the Webdriver sampler and Firefox driver config. When I try to run the test plan, nothing happens. There is nothing recorded in the View Results Tree window, and the remaining test indicator in the top right hand corner counts down to 0 without anything happening.
When I deactivate the Webdriver Sampler and Firefox driver config elements, the remaining tests run without a problem.
Is there a bug with this software, or am I missing something? My code is below, if that helps.
var pkg = JavaImporter(org.openqa.selenium)
WDS.sampleResult.sampleStart()
WDS.browser.get('https://test.test.test.test') var username =
WDS.browser.findElement(pkg.By.id('USERNAME')).sendKeys([WDS.args[0]])
var password =
WDS.browser.findElement(pkg.By.id('PASSWORD')).sendKeys([WDS.args[1])
WDS.sampleResult.sampleEnd()
I have installed firefox 26, as this is the recommended supported browser, so it's not that there's no compatible browser.
My main question is this - Why doesn't the browser window open? Why do the other tests in the test plan fail to run when the config elements are active?
In 99% of cases the answer should be in jmeter.log file. In the meantime a couple of recommendations:
add the following line to system.properties file (lives in the /bin folder of your JMeter installation)
webdriver.firefox.bin=/path/to/your/firefox.exe
See https://code.google.com/p/selenium/wiki/FirefoxDriver page for other Firefox-related properties
locate all duplicate http* libraries like httpcore*.jar httpmime.jar etc. and remove the ones with lesser version
restart JMeter to pick the property and the changes up
Check out The WebDriver Sampler: Your Top 10 Questions Answered guide for other tips and tricks
You need to make sure you provided the full path of the Firefox driver in the jp#gc config element.
I have installed firebug for FF. But when i start firefox it always starts some default ff version, i dont' know where selenium finds it.
I already googled alot, tried to use different firefoxbinary:
System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
final File firefoxPath = new File(System.getProperty("webdriver.firefox.bin")) ;
FirefoxBinary firefoxBinary= new FirefoxBinary(firefoxPath);
firefox = new FirefoxDriver(firefoxBinary,null);
I tried to use different ff profile:
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.9.1");
Alas, it does not work!
1. I don't know where to change/find webdriver.firefox.bin
2. I have tried changing path as environment variable,still no progress
maybe I m doing something wrong?
By default, Selenium will open a "vanilla" Firefox profile. If you want to have it launch with your profile, you can do that, but you have to select which profile you want to use. I will warn you that you often don't want to have your regular profile used because you'd like a clean, consistent working environment.
But you could certainly:
set up a profile (call it, for instance, selenium-profile using
Firefox's profile manager
run Firefox choosing that profile--from
Windows's Run dialog run "c:\Program Files(x86)\Mozilla
Firefox\firefox.exe" - P" or the equivalent path to FF if you are
32-but.
install Firebug using that profile.
then choose that profile when you launch your tests.
For information about how to do all this, look at this article.
Then, in your code, you can just call that profile. Step 3 in the article linked above shows how to do this.
Firefoxdriver starts a new default profile on each instance and this profile will be created in your temp folder and will be deleted after you quit the driver. There might be some old instances of ff profile which contains older version of firebug in your temp folder which might be not be deleted as webdriver quited unexpectedly.Try clearing your temp. It might help you as it did for me.