How to enable all extensions in chrome://extensions/ page with selenium? - selenium

I have pre-installed extensions in my profiles, but they are turned off. I'm trying to turn them on using selenium, but it doesn't find the elements. And writes "Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[#id="enableToggle"]"}" enter image description here

Related

Get updated tags of html in chromeDriver using selenium after click in C#

Working on Selenium automation testing after a click on button <ViewStatement> webpage gets updated with pdf link and some other tags but it is not updating into ChromeDriver driver object
I already tried like PageSource & hit same url into another ChromeDriver driver1 but still not working.
link - https://mfs.kfintech.com/
Code -
driver.FindElement(By.XPath("//input[#value='View Statement']")).Click();
before this click the page is completely loaded into the driver but after click page doesn't reloaded but still some tags are inserted into the same page with same link before and after click so i want whole page after click.
ViewStatement does not exist on link page after login it is there.

"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 make inspect window active using selenium python?

I am trying to automate a plugin in chrome browser. It requires opening an inspect window and perform operation on inspect window. I am able to open inspect window using robot class and navigate among inspect GUI elements but cannot do HTML DOM operation in inspect window. Inspect window contains iframes but I am not able to switch to those iframes from main page. When I try to list the iframes on a active page it only shows iframes from the main page not from the inspect window. I want to switch to inspect window using iframes or any other way if there is any. The code I have written so far is
from pyrobot import Robot
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
browser = webdriver.Chrome()
browser.get('https://chrome.google.com/webstore/detail/dynamic-assessment-plugin/fnapgcgphlfhecijolobjodbbnjjpdga')
browser.maximize_window()
browser.implicitly_wait(15)
browser.find_element_by_css_selector("[aria-label='Add to Chrome']").click()
time.sleep(3)
robot = Robot()
robot.addExtension() # customized Robot class to add extension
robot.newtab() # customized Robto class for new tab
browser.switch_to.window(browser.window_handles[1])
browser.get('http://www.walmart.com')
time.sleep(8)
robot.inspectElement() # Customized Robot class for inspecting (Ctrl+shift+i)
While you create chromedriver object in C# this will work,
you need to provide profile by adding arguments in chromeoptions,
ChromeOptions options = new ChromeOptions();
options.AddArguments("--auto-open-devtools-for-tabs");
browser = new ChromeDriver(DrivePath, options, TimeSpan.FromSeconds(100));
You can also try to press F12 it will open inspect window
then you can use Robot class or Windows. Forms library for automation scripts manae multiple window Forms.
Your code is in python same answers are alredy provided for java and C#.
You can also refer more at:
How to open Chrome Developer console in Selenium WebDriver using JAVA
How do you automatically open the Chrome Devtools tab within Selenium (C#)?

Phantomjs Behat form field not found when executing in my server

everyone, could I have some help please ?
I try to run a test with Behat/Mink and Phantomjs. It works locally without Phantomjs, but not on my server.
When I launch my tests, I've got this problem :
#javascript
Scenario: Searching for a page that does NOT exist
Given I am on "http://fr.wikipedia.org/wiki/Wikip%C3%A9dia:Accueil_principal"
When I fill in "searchInput" with "Glory Driven Development"
Form field with id|name|label|value "searchInput" not found.
My settings in behat.yml is as following
phantomjs:
context:
class: 'FeatureContext'
extensions:
Behat\MinkExtension\Extension:
goutte: ~
selenium2:
wd_host: "http://localhost:8643/wd/hub"
capabilities:
proxy:
proxyType: direct
My test is as following
#javascript
Scenario: Searching for a page that does NOT exist
Given I am on "http://fr.wikipedia.org/wiki/WikipC3%A9dia:Accueil_principal"
When I fill in "searchInput" with "Glory Driven Development"
And I press "searchButton"
Then I should see "Search results"
I can't understand why it says : "Form field with id|name|label|value "searchInput" not found". I have launched phantomjs and even selenium.
Does someone has an idea ? Thank you
I was trying same scenario today.
Driver is complaining about not finding the element. So I debug a bit the test case and found that the page browsed by driver was different than the one expected.
When the driver does: $this->getSession()->getPage(). Be sure you are in the expected page and receiving expected html.

How to deal with Java warning popup?

While running WebDriver automation scripts I came across a situation where it is trying to open a page which contain one segment with live camera (Made with Java applet). Once script reaches to this page - a Security Warning alert (with allow and not allow) shows up and blocks the execution process. Is this something that anyone faced before - actually I am looking for an option to block this security warning to get displayed on the page.
A popup is coming where i want to click on the "Allow". How to move the focus to the new popup window and click on Allow.
Can anyone please help me for the above problem?
I was having problems accepting the java applet "Allow"
My solution was to create a firefox profile that had the settings to always activate the plugin:
FirefoxProfile fp = new FirefoxProfile();
fp.setAcceptUntrustedCertificates( true );
fp.setPreference( "security.enable_java", true );
fp.setPreference( "plugin.state.java", 2 );
WebDriver d = new FirefoxDriver( fp );
Where plugin.state.java:
plugin.state.java = 0 --> never activate
plugin.state.java = 1 --> ask to activate
plugin.state.java = 2 --> always activate
This might get you closer...
Selenium uses a different firefox profile because Java was inactive for me and I did not have my firebug plugin in the Firefox browser Selenium launched. I would have to open another Firefox to use Firebug.
I found my default Firefox profile by searching %appdata% in the start menu then clicking on Roaming/ Mozilla/ Firefox/ Profile/ and then it gave my default profile name.
You can also open the firefox help menu (? logo) & click troubleshoot info... click Show Profile Folder
I then configured selenium to use my default profile so Java was enabled and Firebug was available in the browser Selenium launched:
Make sure that you use "/" in selenium even though it may use "\" in the windows path location
fp = webdriver.FirefoxProfile('C:/Users/xxx/AppData/Roaming/Mozilla/Firefox/Profiles/41s7nq9o.default')
driver = webdriver.Firefox(fp)
driver.get('www.stackoverflow.com')
where 41s7nq9o.default is the name of your default profile