The method attachToEdgeChrome() is undefined for the type InternetExplorerOptions using selenium-server-4.0.0-alpha-2 - selenium

I want test the IE mode for Edge browser with Selenium. I found the solution on the MS site here:
https://learn.microsoft.com/en-us/microsoft-edge/webdriver-chromium/ie-mode?tabs=java
I am using the following code as given in the above link:
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerOptions;
InternetExplorerOptions ieOptions = new InternetExplorerOptions();
ieOptions.attachToEdgeChrome();
ieOptions.withEdgeExecutablePath("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");
WebDriver driver = new InternetExplorerDriver(ieOptions);
I can get the error that the methods "attachToEdgeChrome()" and "withEdgeExecutablePath()" are not defined in the InternetExplorerOptions. Is there anything I am missing here?
Note: My selenium jar is selenium-server-4.0.0-alpha-2.jar

As per the ChangeLogs 0f Selenium v4.0.0.0-alpha-2:
Add Chromium-based Edge support. This involves adding a new Chromium driver to the tree too.
So ideally, the code block from the documentation Use Internet Explorer Driver to automate IE mode in Microsoft Edge should have worked seamlessly.
However, as per best practices instead of using the alpha and beta releases, you should always prefer the GA releases to execute your tests and you can pickup anyone from the following options:
Selenium v4.1.3
Selenium v4.1.2
Selenium v4.1.1
Selenium v4.1.0
Selenium v4.0.0

Related

Install and use Geckodriver on Heroku correctly [duplicate]

from selenium import webdriver;
browser= webdriver.Firefox();
browser.get('http://www.seleniumhq.org');
When I try to run this code, it gives me an error message:
Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line.
Any thoughts-highly appreciated!
This error message...
Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line.
...implies that the GeckoDriver was unable to find the Firefox binary at the default location. Additionally you haven't passed the moz:firefoxOptions.binary capability.
Solution
Possibly within your system firefox is installed in a custom location and these cases you need to pass the absolute path of the Firefox binary through the moz:firefoxOptions.binary capability as follows:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.binary_location = r'C:\Program Files\Mozilla Firefox\firefox.exe'
driver = webdriver.Firefox(executable_path=r'C:\WebDrivers\geckodriver.exe', options=options)
driver.get('http://google.com/')
References
You can find a couple of relevant detailed discussion in:
SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary'
InvalidArgumentException: Message: binary is not a Firefox executable error using GeckoDriver Firefox Selenium and Python
Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided
Firefox was not installed on my system at all. That's why this error came up.
same issue here:
Environment
OS: Mac
Not install Firefox application
has installed geckodriver, can found in PATH
Error Reason: Not installed Firefox
Solution: (goto firefox official site to download and) install Firefox
Before this ensure that path variable has include for geckodriver click here to download driver and run below python script.
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.binary_location = r'C:\Program Files\Mozilla Firefox\firefox.exe'
driver = webdriver.Firefox(options=options)
driver.get('http://google.com/')
I have uninstalled firefox and installed it again which resolved my issue.
You should download appropriate web driver from https://github.com/mozilla/geckodriver/releases and put it into folder where your py file is. Also you can put it anywhere as long as the location of the file it is in your system path.
Selenium uses a web driver (a specific one for each web browser) in order to communicate with the browser installed on your system (Firefox in your case).
To use Firefox, you have to:
Download its web driver from
https://github.com/mozilla/geckodriver/releases
Put the web driver in a specific location in the file system (same folder as the python script for example)
Add the web driver location path when initializing in the python code.
So the final code would look like this:
from selenium import webdriver
browser = webdriver.Firefox('./geckodriver')
browser.get('https://www.python.org/')
Note: Sometimes a newer version of the web driver isn't compatible with an older version of the browser installed on your system.
I have encountered the same problem (Windows, Firefox v99, Selenium 4.1.4, geckodriver 0.31.0), the path to exe file and the driver initialisation were set correctly, solved the issue by changing the win32 by win64 version of geckodriver
as a side note for selenium/firefox (but with C#, not Python), this issue is quite relevant now in the sense that firefox location looks to be stored in windows in a new regedit location. Indeed geckodriver is looking in regedit location documented here:
HKEY_LOCAL_MACHINE\SOFTWARE WOW6432Node\Mozilla\Mozilla Firefox\[VERSION]\Main\PathToExe
HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox\[VERSION]\Main\PathToExe
Source:
https://developer.mozilla.org/en-US/docs/Web/WebDriver/Capabilities/firefoxOptions
when on my machine it is there:
HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox 109.0\bin
With the version number stored here:
HKEY_LOCAL_MACHINE\SOFTWARE\mozilla.org\Mozilla
and I set the selenium driver with C# Api with (path hardcoded for the poc):
var options = new FirefoxOptions();
...
options.BrowserExecutableLocation = #"C:\Program Files\Mozilla Firefox\firefox.exe";
Driver = new FirefoxDriver(options);
Regards
You need to download geckodriver.
https://github.com/mozilla/geckodriver/releases
from selenium import webdriver;
browser= webdriver.Firefox('./geckodriver');
browser.get('http://www.seleniumhq.org');

How to open Chrome Browser in Ubuntu with chromedriver in Selenium [duplicate]

I am trying to launch chrome with an URL, the browser launches and it does nothing after that.
I am seeing the below error after 1 minute:
Unable to open browser with url: 'https://www.google.com' (Root cause: org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
(Driver info: chromedriver=2.39.562718 (9a2698cba08cf5a471a29d30c8b3e12becabb0e9),platform=Windows NT 10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)
My configuration:
Chrome : 66
ChromeBrowser : 2.39.56
P.S everything works fine in Firefox
Thumb rule
A common cause for Chrome to crash during startup is running Chrome as root user (administrator) on Linux. While it is possible to work around this issue by passing --no-sandbox flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Chrome as a regular user instead.
This error message...
org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Your code trials and the versioning information of all the binaries would have given us some hint about what's going wrong.
However as per Add --disable-dev-shm-usage to default launch flags seems adding the argument --disable-dev-shm-usage will temporary solve the issue.
If you desire to initiate/span a new Chrome Browser session you can use the following solution:
System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized"); // open Browser in maximized mode
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("--no-sandbox"); // Bypass OS security model
WebDriver driver = new ChromeDriver(options);
driver.get("https://google.com");
disable-dev-shm-usage
As per base_switches.cc disable-dev-shm-usage seems to be valid only on Linux OS:
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// The /dev/shm partition is too small in certain VM environments, causing
// Chrome to fail or crash (see http://crbug.com/715363). Use this flag to
// work-around this issue (a temporary directory will always be used to create
// anonymous shared memory files).
const char kDisableDevShmUsage[] = "disable-dev-shm-usage";
#endif
In the discussion Add an option to use /tmp instead of /dev/shm David mentions:
I think it would depend on how are /dev/shm and /tmp mounted.
If they are both mounted as tmpfs I'm assuming there won't be any difference.
if for some reason /tmp is not mapped as tmpfs (and I think is mapped as tmpfs by default by systemd), chrome shared memory management always maps files into memory when creating an anonymous shared files, so even in that case shouldn't be much difference. I guess you could force telemetry tests with the flag enabled and see how it goes.
As for why not use by default, it was a pushed back by the shared memory team, I guess it makes sense it should be useing /dev/shm for shared memory by default.
Ultimately all this should be moving to use memfd_create, but I don't think that's going to happen any time soon, since it will require refactoring Chrome memory management significantly.
Reference
You can find a couple of detailed discussions in:
unknown error: DevToolsActivePort file doesn't exist error while executing Selenium UI test cases on ubuntu
Tests fail immediately with unknown error: DevToolsActivePort file doesn't exist when running Selenium grid through systemd
Outro
Here is the link to the Sandbox story.
I started seeing this problem on Monday 2018-06-04. Our tests run each weekday. It appears that the only thing that changed was the google-chrome version (which had been updated to current) JVM and Selenium were recent versions on Linux box ( Java 1.8.0_151, selenium 3.12.0, google-chrome 67.0.3396.62, and xvfb-run).
Specifically adding the arguments "--no-sandbox" and "--disable-dev-shm-usage" stopped the error.
I'll look into these issues to find more info about the effect, and other questions as in what triggered google-chrome to update.
ChromeOptions options = new ChromeOptions();
...
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
We were having the same issues on our jenkins slaves (linux machine) and tried all the options above.
The only thing helped is setting the argument
chrome_options.add_argument('--headless')
But when we investigated further, noticed that XVFB screen doesn't started property and thats causing this error. After we fix XVFB screen, it resolved the issue.
I had the same problem in python. The above helped. Here is what I used in python -
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('/path/to/your_chrome_driver_dir/chromedriver',chrome_options=chrome_options)
I was facing the same issue recently and after some trial and error it worked for me as well.
MUST BE ON TOP:
options.addArguments("--no-sandbox"); //has to be the very first option
BaseSeleniumTests.java
public abstract class BaseSeleniumTests {
private static final String CHROMEDRIVER_EXE = "chromedriver.exe";
private static final String IEDRIVER_EXE = "IEDriverServer.exe";
private static final String FFDRIVER_EXE = "geckodriver.exe";
protected WebDriver driver;
#Before
public void setUp() {
loadChromeDriver();
}
#After
public void tearDown() {
if (driver != null) {
driver.close();
driver.quit();
}
}
private void loadChromeDriver() {
ClassLoader classLoader = getClass().getClassLoader();
String filePath = classLoader.getResource(CHROMEDRIVER_EXE).getFile();
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeDriverService service = new ChromeDriverService.Builder()
.usingDriverExecutable(new File(filePath))
.build();
ChromeOptions options = new ChromeOptions();
options.addArguments("--no-sandbox"); // Bypass OS security model, MUST BE THE VERY FIRST OPTION
options.addArguments("--headless");
options.setExperimentalOption("useAutomationExtension", false);
options.addArguments("start-maximized"); // open Browser in maximized mode
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.merge(capabilities);
this.driver = new ChromeDriver(service, options);
}
}
GoogleSearchPageTraditionalSeleniumTests.java
#RunWith(SpringRunner.class)
#SpringBootTest
public class GoogleSearchPageTraditionalSeleniumTests extends BaseSeleniumTests {
#Test
public void getSearchPage() {
this.driver.get("https://www.google.com");
WebElement element = this.driver.findElement(By.name("q"));
assertNotNull(element);
}
}
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
In my case in the following environment:
Windows 10
Python 3.7.5
Google Chrome version 80 and corresponding ChromeDriver in the path C:\Windows
selenium 3.141.0
I needed to add the arguments --no-sandbox and --remote-debugging-port=9222 to the ChromeOptions object and run the code as administrator user by lunching the Powershell/cmd as administrator.
Here is the related piece of code:
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('--disable-infobars')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--no-sandbox')
options.add_argument('--remote-debugging-port=9222')
driver = webdriver.Chrome(options=options)
I ran into this problem on Ubuntu 20 with Python Selenium after first downloading the chromedriver separately and then using sudo apt install chromium-browser Even though they were the same version this kept happening.
My fix was to use the provided chrome driver that came with the repo package located at
/snap/bin/chromium.chromedriver
driver = webdriver.Chrome(chrome_options=options, executable_path='/snap/bin/chromium.chromedriver')
Update:
I am able to get through the issue and now I am able to access the chrome with desired url.
Results of trying the provided solutions:
I tried all the settings as provided above but I was unable to resolve the issue
Explanation regarding the issue:
As per my observation DevToolsActivePort file doesn't exist is caused when chrome is unable to find its reference in scoped_dirXXXXX folder.
Steps taken to solve the issue
I have killed all the chrome processes and chrome driver processes.
Added the below code to invoke the chrome
System.setProperty("webdriver.chrome.driver","pathto\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("useAutomationExtension", false);
WebDriver driver = new ChromeDriver(options);
driver.get(url);
Using the above steps I was able to resolve the issue.
Thanks for your answers.
In my case it was problem with CI Agent account on ubuntu server, I solved this using custom --user-data-dir
chrome_options.add_argument('--user-data-dir=~/.config/google-chrome')
My account used by CI Agent didn't have necessary permissions, what was interesting everything was working on root account
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--profile-directory=Default')
chrome_options.add_argument('--user-data-dir=~/.config/google-chrome')
driver = webdriver.Chrome(options=chrome_options)
url = 'https://www.google.com'
driver.get(url)
get_url = driver.current_url
print(get_url)
There is lot of possible reasons for the RESPONSE InitSession ERROR unknown error: DevToolsActivePort file doesn't exist error message (as we can see from the number of answers for this question). So let's dive deeper to explain what exactly this error message means.
According to chromedriver source code the message is created in ParseDevToolsActivePortFile method. This method is called from the loop after launching chrome process.
In the loop the driver check if the chrome process is still running and if the ParseDevToolsActivePortFile file was already created by chrome. There is a hardcoded 60s timeout for this loop.
I see two possible reasons for this message:
Chrome is really slow during startup - for example due to lack of system resources - mainly CPU or memory. In this case it can happen that sometimes chrome manage to start in time limit and sometimes not.
There is another issue which prevents chrome to start - missing or broken dependency, wrong configuration etc. In such case this error message is not really helpful and you should find another log message which explain the true reason of the failure.
It happens when chromedriver fails to figure out what debugging port chrome is using.
One possible cause is an open defect with HKEY_CURRENT_USER\Software\Policies\Google\Chrome\UserDataDir
But in my last case, it was some other unidentified cause.
Fortunately setting port number manually worked:
final String[] args = { "--remote-debugging-port=9222" };
options.addArguments(args);
WebDriver driver = new ChromeDriver(options);
As stated in this other answer:
This error message... implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Among the possible causes, I would like to mention the fact that, in case you are running an headless Chromium via Xvfb, you might need to export the DISPLAY variable: in my case, I had in place (as recommended) the --disable-dev-shm-usage and --no-sandbox options, everything was running fine, but in a new installation running the latest (at the time of writing) Ubuntu 18.04 this error started to occurr, and the only possible fix was to execute an export DISPLAY=":20" (having previously started Xvfb with Xvfb :20&).
You can get this error simply for passing bad arguments to Chrome. For example, if I pass "headless" as an arg to the C# ChromeDriver, it fires up great. If I make a mistake and use the wrong syntax, "--headless", I get the DevToolsActivePort file doesn't exist error.
I was stuck on this for a very long time and finally fixed it by adding this an additional option:
options.addArguments("--crash-dumps-dir=/tmp")
I know it's an old question and it already has a lot of answers. However, I ran into this issue, bumped into this thread and none of the proposed solutions helped. After spending a few days(!) on it I finally found a solution:
My problem was that I was using the selenium/standalone-chrome image on a MacBook with M1 chip. After switching to seleniarm/standalone-chromium everything finally started to work.
I had the same issue, but in my case chrome previously was installed in user temp folder, after that was reinstalled to Program files. So any of solution provided here was not help me. But if provide path to chrome.exe all works:
chromeOptions.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
I hope this helps someone =)
In my case it happened when I've tried to use my default user profile:
...
options.addArguments("user-data-dir=D:\\MyHomeDirectory\\Google\\Chrome\\User Data");
...
This triggered chrome to reuse processes already running in background, in such a way, that process started by chromedriver.exe was simply ended.
Resolution: kill all chrome.exe processes running in background.
update capabilities in conf.js as
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['todo-spec.js'],
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['--disable-gpu', '--no-sandbox', '--disable-extensions', '--disable-dev-shm-usage']
}
},
};
Old question but a similar issue nearly drove me to insanity so sharing my solution. None of the other suggestions fixed my issue.
When I updated my Docker image Chrome installation from an old version to Chrome 86, I got this error. My setup was not identical but we were instantiating Chrome through a selenium webdriver.
The solution was to pass the options as goog:chromeOptions hash instead of chromeOptions hash. I truly don't know if this was a Selenium, Chrome, Chromedriver, or some other update, but maybe some poor soul will find solace in this answer in the future.
For Ubuntu 20 it did help me to use my systems chromium driver instead of the downloaded one:
# chromium which
/snap/bin/chromium
driver = webdriver.Chrome('/snap/bin/chromium.chromedriver',
options=chrome_options)
And for the downloaded webdriver looks like it needs the remote debug port --remote-debugging-port=9222 to be set, as in one of the answers (by Soheil Pourbafrani):
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--remote-debugging-port=9222")
driver = webdriver.Chrome('<path_to>/chromedriver', options=chrome_options)
Date 9/16/2021
Everything works fine running chrome with selenium locally with python inside the docker hosted ubuntu container. When attempting to run from Jenkins the error above is returned WebDriverException: unknown error: DevToolsActivePort
Environment:
-Ubuntu21.04 inside a docker container with RDP access.
-chromedriver for chrome version: 93
Solution:
Inside the python file that starts the browser I had to set the DISPLAY environment variable using the following lines:
import os
os.environ['DISPLAY'] = ':10.0'
#DISPLAY_VAR = os.environ.get('DISPLAY')
#print("DISPLAY_VAR:", DISPLAY_VAR)
In my case, I was trying to create a runnable jar on Windows OS with chrome browser and want to run the same on headless mode in unix box with CentOs on it. And I was pointing my binary to a driver that I have downloaded and packaged with my suite. For me, this issue continue to occur irrespective of adding the below:
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--no-sandbox");
System.setProperty("webdriver.chrome.args", "--disable-logging");
System.setProperty("webdriver.chrome.silentOutput", "true");
options.setBinary("/pointing/downloaded/driver/path/in/automationsuite");
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("window-size=1024,768"); // Bypass OS security model
options.addArguments("--log-level=3"); // set log level
options.addArguments("--silent");//
options.setCapability("chrome.verbose", false); //disable logging
driver = new ChromeDriver(options);
Solution that I've tried and worked for me is, download the chrome and its tools on the host VM/Unix box, install and point the binary to this in the automation suite and bingo! It works :)
Download command:
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
Install command:
sudo yum install -y ./google-chrome-stable_current_*.rpm
Update suite with below binary path of google-chrome:
options.setBinary("/opt/google/chrome/google-chrome");
And.. it works!
I also faced this issue while integrating with jenkins server, I was used the root user for jenkin job, the issue was fixed when I changed the user to other user. I am not sure why this error occurs for the root user.
Google Chrome Version 71.0
ChromeDriver Version 2.45
CentOS7 Version 1.153
I run selenium tests with Jenkins running on an Ubuntu 18 LTS linux. I had this error until I added the argument 'headless' like this (and some other arguments):
ChromeOptions options = new ChromeOptions();
options.addArguments("headless"); // headless -> no browser window. needed for jenkins
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("--no-sandbox"); // Bypass OS security model
ChromeDriver driver = new ChromeDriver(options);
driver.get("www.google.com");
Had the same issue. I am running the selenium script on Google cloud VM.
options.addArguments("--headless");
The above line resolved my issue. I removed the other optional arguments. I think the rest lines of code mentioned in other answers did not have any effect on resolving the issue on the cloud VM.
in my case, when i changed the google-chrome and chromedriver version, the error was fixed :)
#google-chrome version
[root#localhost ~]# /usr/bin/google-chrome --version
Google Chrome 83.0.4103.106
#chromedriver version
[root#localhost ~]# /usr/local/bin/chromedriver -v
ChromeDriver 83.0.4103.14 (be04594a2b8411758b860104bc0a1033417178be-refs/branch-heads/4103#{#119})
ps: selenium verison was 3.9.1
No solution worked for my. But here is a workaround:
maxcounter=5
for counter in range(maxcounter):
try:
driver = webdriver.Chrome(chrome_options=options,
service_log_path=logfile,
service_args=["--verbose", "--log-path=%s" % logfile])
break
except WebDriverException as e:
print("RETRYING INITIALIZATION OF WEBDRIVER! Error: %s" % str(e))
time.sleep(10)
if counter==maxcounter-1:
raise WebDriverException("Maximum number of selenium-firefox-webdriver-retries exceeded.")
It seems there are many possible causes for this error. In our case, the error happened because we had the following two lines in code:
System.setProperty("webdriver.chrome.driver", chromeDriverPath);
chromeOptions.setBinary(chromeDriverPath);
It's solved by removing the second line.
I ran into same issue, i am using UBUNTU, PYTHON and OPERA browser. in my case the problem was originated because i had an outdated version of operadriver.
Solution:
1. Make sure you install latest opera browser version ( do not use opera beta or opera developer), for that go to the official opera site and download from there the latest opera_stable version.
Install latest opera driver (if you already have an opera driver install, you have to remove it first use sudo rm ...)
wget https://github.com/operasoftware/operachromiumdriver/releases/download/v.80.0.3987.100/operadriver_linux64.zip
unzip operadriver_linux64.zip
sudo mv operadriver /usr/bin/operadriver
sudo chown root:root /usr/bin/operadriver
sudo chmod +x /usr/bin/operadriver
in my case latest was 80.0.3987 as you can see
Additionally i also installed chromedriver (but since i did it before testing, i do not know of this is needed) in order to install chromedriver, follow the steps on previous step :v
Enjoy and thank me!
Sample selenium code
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Opera()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.quit()
I came across the same problem, in my case there are two different common user userA and userB in Linux system.
userA first run the selinium programe which start chrome browswer with ChromeDriver successfully, when it came to userB, the DevToolsActivePort file doesn't exist error occur.
I tried the --remote-debugging-port=9222 option, but it lead to a new exception:
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
The I ran google-chome directory and see the following error:
mkdir /tmp/Crashpad/new: Permission denied (13)
The I search the problem and got this:
https://johncylee.github.io/2022/05/14/chrome-headless-%E6%A8%A1%E5%BC%8F%E4%B8%8B-devtoolsactiveport-file-doesn-t-exist-%E5%95%8F%E9%A1%8C/
chrome_options.add_argument(f"--crash-dumps-dir={os.path.expanduser('~/tmp/Crashpad')}")
Thanks to #johncylee.

Selenium - Edge - How to start a webdriver session with work profile?

My application does not have a login page to get authenticated. It uses my organizational email id (SSO) to authenticate my access to the application. I am using Version 80.0.361.66 (Official build) (64-bit) of Microsoft Edge.
driver = webdriver.Edge()
driver.maximize_window()
selenium version - selenium==3.141.0
This edge session does not use my work profile . It opens a new session because of which my work profile is not loaded and my access to the application is denied. However, I did try to update the version of selenium to use EdgeOptions. But, that didn't work as well. Below is the code :
options = webdriver.EdgeOptions()
options.add_argument("user-data-dir=C:\\Users\\Ajmal.Moideen\\AppData\\Local\\Microsoft\\Edge\\User Data")
driver = webdriver.Edge(options=options)
driver.maximize_window()
selenium version=4.0.0a3
Here's how I got it to work - I am using Chromium Edge 85.0.564.51 with Selenium 3.141.0.
Selenium 3.141.0 from pip doesn't seem to support new Chromium-based Edge Webdriver, but Microsoft supplies it in their msedge-selenium-tools package (better documentation here) as mentioned by Matthias' comment on your question.
First, grab the Chromium Edge webdriver here - get the version that matches your version of Edge (go to chrome:version in Edge to see what version you are running). Put the webdriver somewhere convenient, you need to set driverpath below to point to it.
Install the pip packages:
pip install msedge-selenium-tools selenium==3.141
In your code, import the msedge-selenium-tools Webdriver and Options modules and build the webdriver as shown:
from msedge.selenium_tools import Edge, EdgeOptions
...
options = EdgeOptions()
options.use_chromium = True
options.add_argument("--user-data-dir=C:\\Users\\YOUR-USERNAME\\AppData\\Local\\Microsoft\\Edge\\User Data")
options.add_argument("--start-maximized")
driverpath = 'msedgedriver.exe'
driver = Edge(driverpath, options=options)
Voilà, that should do the trick.
P.S.: Even though chrome:version will show your Profile path with a trailing \Default, don't include that in your --user-data-dir argument above, since the driver seems to append \Default to the end.

"Component not initialized" nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)" error with Selenium GeckoDriver and Mozilla

I am trying to execute my code in Firefox, sometimes it works but majority of time i get exception as:
[Exception... "Component not initialized" nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)" location: "JS frame :: chrome://marionette/content/dom.js :: addEventListener :: line 67" data: no]
Its happening from last week, previously it was working fine for me.
NS_ERROR_NOT_INITIALIZED resembles an attempt which was made to use a component or object which has not yet been initialized. These components usually provide an initialization method, often called Init which must be called before any other methods which are being used.
However, this error message...
[Exception... "Component not initialized" nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)" location: "JS frame :: chrome://marionette/content/dom.js :: addEventListener :: line 67" data: no]
...implies that the Marionette threw an error while invoking addEventListener as defined in dom.js
Your code trials and the relevant HTML DOM would have helped us to debug the issue in a better way. However it seems the addEventListener was invoked too early even before the DOM Tree was completely rendered. To be more specific addEventListener was invoked even before the Browser Client (i.e. the Web Browser) have attained 'document.readyState' equal to "complete". Generally once this condition is fulfilled Selenium performs the next line of code.
Solution
A quick solution will be to before you try to interact with any of the element on a fresh loaded webpage you need to induce WebDriverWait for either of the following expected_conditions:
title_is(title)
title_contains(title)
An example
Python:
Code Block:
driver.get("https://stackoverflow.com");
WebDriverWait(driver, 10).until(EC.title_contains("Stack"))
print("Page Title is : "+driver.title)
Console Output:
Page Title is : Stack Overflow - Where Developers Learn, Share, & Build Careers
Java:
Code Block:
driver.get("https://stackoverflow.com");
new WebDriverWait(driver, 10).until(ExpectedConditions.titleContains("Stack"));
System.out.println("Page Title is : "+driver.getTitle());
Console Output:
Page Title is : Stack Overflow - Where Developers Learn, Share, & Build Careers
Additional Considerations
Upgrade JDK to recent levels JDK 8u221.
Upgrade Selenium to current levels Version 3.141.59.
Upgrade GeckoDriver to GeckoDriver v0.25.0 level.
Ensure that the version of the binaries you are using are compatable.
You can find a detailed discussion in Which Firefox browser versions supported for given Geckodriver version?
GeckoDriver is present in the desired location.
GeckoDriver is having executable permission for non-root users.
Upgrade Firefox version to Firefox v69.0 levels.
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your Test as a non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
References
You can find a couple of relevant discussions in:
WebDriverException: Message: Exception… “Failure” nsresult: “0x80004005 (NS_ERROR_FAILURE)” while saving a large html file using Selenium Python
[org.openqa.selenium.WebDriverException: Exception… “Component not initialized” error using GeckoDriver and Tor browser with Selenium Java
Outro
Occur the 'NS_ERROR_NOT_INITIALIZED' when switching the window to bottom dock.
It seems you're suffering from Geckodriver Issue 1263, you can try the following workarounds:
Update Selenium client library to the latest stable which is 3.141.59 as of now, it's better to use package management system like Maven or Gradle as update of dependencies libraries might be required. If you're not using Java check out Web - Desktop and Mobile Browsers article for code examples for different Selenium client languages like JavaScript, Python, C#, etc.
Make sure to use the latest version of Firefox
Make sure to use the latest version of Geckodriver
If you will be still experiencing problems you can consider raising a new issue in the Geckodriver project, be prepared to provide as much information as possible (the same applies to next questions here if any)
On my case, some configs were wrong. I was trying to block pop-up downloads, but something went wrong.Here is the code that I had to remove, and it worked (on this specific case):
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.dir", "C:\\Temp");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv");
profile.setPreference("pdfjs.disabled", true);
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.panel.shown", false);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
capabilities.setCapability(CapabilityType.ELEMENT_SCROLL_BEHAVIOR, 1);
driver = new FirefoxDriver(capabilities);

How to install extension permanently in geckodriver

I need to test Firefox using an extension. I want to automate the test and visit several websites.
I installed Selenium and it opens in geckodriver. However, the extension is not there. I can install it manually from about:debugging but the problem is that I want the Selenium test to launch the gecko driver while the extension is already there. How to do this? How to install the extension permanently in the geckodriver so it is there when I launch the geckodriver from selenium?
EDIT:
I also tried to install the extension (add it to the browser) from the Firefox extensions websites. It gets added but once I close the gecko window, the extension disappear in the next run. How to install it permanently?
Note: OP didn't specify a language, so this answer is for Python. The other Selenium WebDriver language bindings have similar mechanisms for creating profiles and adding extensions.
You can install the Extension each time you instantiate the driver.
First, download the extension (XPI file) you want from: https://addons.mozilla.org.
Then, in your code... create a FirefoxProfile() and use the add_extension() method to add the extension. Then you can instantiate a driver using that profile.
For example, this will launch Firefox with a newly created profile containing the "HTTPS Everywhere" extension:
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.add_extension(extension='https_everywhere-2019.1.31-an+fx.xpi')
driver = webdriver.Firefox(firefox_profile=profile)
You need to launch geckdriver with an exisitng profile by specifying the profile path of firefox
For python you can do it by this:
profile = FirefoxProfile('/home/student/.mozilla/firefox/gwi6uqpe.Default') // change this path
browser = webdriver.Firefox(firefox_profile=profile)
For C# you can do this:
string path = #"C:\Users\username\AppData\Local\Mozilla\Firefox\Profiles\myi5go1k.default";
FirefoxProfile ffprofile = new FirefoxProfile(path);
Driver = new FirefoxDriver(ffprofile);
I found that this was warking for me:
from selenium import webdriver
driver_path = r"G:\Libs\geckoDriver\firefox\geckodriver.exe"
driver = webdriver.Firefox(executable_path=driver_path)
path = r"G:\Libs\ext\uBlock0_1.38.7b5.firefox.signed.xpi"
driver.install_addon(path, temporary=True)
driver.profile = webdriver.FirefoxProfile()
driver.profile.add_extension(path)
driver.profile.set_preference("security.fileuri.strict_origin_policy", False)
driver.profile.update_preferences()`enter code here`
Reference:
[Python] https://cyruslab.net/2020/08/26/python-adding-extension-to-geckodriver-with-selenium/
You can install an extension/addon permanently within a specific Firefox Profile and use it. To achieve that you need follow the below mentioned steps:
You need to create a new Firefox Profile manually (e.g. FirefoxExtensionProfile) following the instructions at Creating a new Firefox profile on Windows.
Open a Firefox Browsing session manually and invoke the url https://addons.mozilla.org/en-US/firefox/
In the Search Box search for an extension e.g. HTTPS Everywhere.
Click on the search result and install / enable (incase previously installed and currently disabled) the extension.
Now you can use the following Java solution to open the Firefox Profile FirefoxExtensionProfile containing the extension HTTPS Everywhere
Code Block:
package A_MozillaFirefox;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.ProfilesIni;
public class A_FirefoxProfile_dc_opt {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile testprofile = profile.getProfile("FirefoxExtensionProfile");
FirefoxOptions opt = new FirefoxOptions();
opt.setProfile(testprofile);
WebDriver driver = new FirefoxDriver(opt);
driver.get("https://www.google.com");
}
}
Browser Snapshot:
Reference
You can find a couple of relevant discussions in:
[Python] How to load extension within chrome driver in selenium with python
[Python] How to install Chrome Extension using Selenium & Python