Selenium webdriver trying to access popup context - selenium-webdriver

I'm trying to authorize Selenium to install an extension but there's no way to get to the popup context:
My code:
driver = webdriver.Firefox()
#The extension
driver.get("https://addons.mozilla.org/es/firefox/addon/ether-metamask/")
time.sleep(1)
#Perform the act that opens the new window
driver.find_element_by_xpath("//*[contains(text(), 'Agregar a Firefox')]").click()
Popup that shows up:
The popup that shows next cannot be inspected by the browser and I tried to access it by driver.switch_to_alert but that was worthless.

Related

Simulator Freezes With BrowserComponent

I have a BrowserComponent that loads a specific URL.
BrowserComponent browser = new BrowserComponent();
browser.setURL(url);
browser.addBrowserNavigationCallback(url -> {
...
return false;
});
This URL redirects to another, with the new page showing a JS alert dialog.
The Simulator freezes without exception or error while attempting to load the page with a dialog, and the only choice left is closing the Sim.
How do I handle a JS dialog in a BrowserComponent?
It will be great if I can dismiss an alert dialog automagically.
My run log:
JCEF Version = 84.4.1.262
CEF Version = 84.4.1
Chromium Version = 84.0.4147.105
initialize on Thread[AWT-EventQueue-0,6,main] with library path ~\.codenameone\cef\lib\win64
Added scheme search://
Added scheme client://
Added scheme cn1stream://
DevTools listening on ws://127.0.0.1:56113/devtools/browser/8a42a5d0-5ad5-4838-9027-ee9737d73370
AppHandler.stateHasChanged: NEW
AppHandler.stateHasChanged: INITIALIZING
AppHandler.stateHasChanged: INITIALIZED
Stream was closed
[EDT] 0:0:18,233 - Codename One revisions: 7dd4e7d08b3442d90959477ee52a5ae8c4361b29
[EDT] 0:0:18,234 -
[0322/062422.651:INFO:CONSOLE(22)] "Here I am !!!", source: https://cn1app/streams/1 (22)
This issue has been fixed in Git with this commit:
https://github.com/codenameone/CodenameOne/commit/c4afc9d428a959e2f8dcf37594bed8ae81e467a2
It will be included in the next Cn1 update this Friday.

Robot framework - Selenium - ChromeOptions "Prompt For Download" not working when downloading a file

I'm using robot framework with selenium for automating my web application.
I'm trying to open chrome browser and download a XML file and then parse it from the results folder ${OUTPUT_DIR}.
Every time I'm trying to download any file, chrome browser shows the windows prompt to download the file. I tried using the chrome options to disable the prompt, but it is not working. Please find the piece of code used to invoke chrome browser.
When tried using the regedit - PromptForDownloadLocation variable, it is working fine.. but I want to manage this using chromeOptions
Could you please help me with this.
ChromeDriver version : 79.0.3945.36
Robotframework - SeleniumLibrary version : 3.3.1
Create Webdriver and Open Browser
${CHROME_OPTIONS} = evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
${prefs} = create dictionary download.prompt_for_download=${FALSE} download.directory_upgrade=${TRUE} download.default_directory=${OUTPUT_DIR} safebrowsing.enabled=${TRUE}
call method ${CHROME_OPTIONS} add_experimental_option prefs ${prefs}
create webdriver Chrome chrome_options=${CHROME_OPTIONS}

Aspx aplication dialog pages(or #dialogiframe) fails to load on chrome/chromePortable with chromedriver 76 through selenium

Aspx aplication dialog pages(or #dialogiframe) fails to load on chrome/chromePortable with chromedriver 76 through selenium. When we open any dialog pages in aspx application it opens blank page and selenium fails with NoSuchElement Found exception. However, we tried this manually on same browser versions and it loads perfectly manually.
It happens only when we launch out browser using chrome driver 75+.
Browser: Chrome/ChromePortable 76
Chrome Driver Version : 75.x and higher
Selenium Version : 3.13
Language : C#
We tried with making w3c false in C# with selenium but it doesn't work because of existing issue : https://github.com/SeleniumHQ/selenium/issues/7521
It seems style = 'height:fit-content' blocking the page to load. when we removed the style or changed the style it worked.
var frame = driver.FindElement(By.CssSelector("dialog[open]:last-of-type #dialogiframe")).UnwrapAllLayers();
driver.SwitchTo().Frame(frame);
var element = driver.FindElement(By.CssSelector("td[style = 'height:fit-content']"));
var jsExecutor = (IJavaScriptExecutor)driver;
jsExecutor.ExecuteScript("arguments[0].style=''", element);

Selenium: execute script after Google Tag Manager has loaded

I'm loading a URL in selenium, which uses Google Tag Manager to inject a script.
<script src="http://sample.com/file.js" />
I'm loading the URL in the webdriver using this
await driver.get('https://sample-page-that-uses-gtm.com)
When I go to that URL in my browser (not selenium driver), and manually check the script in the elements tab and console (query selector), I can successfully find the script. However, this is not the case in Selenium. I manually opened console of the Selenium Webdriver and ran a check for the presence of the injected script, but there was none detected.
This is what I ran on the console
document.querySelector('script[src="http://sample.com/file.js"]')
It finds the script on the browser, but not on Webdriver. Is this a problem with using GTM on Selenium?
try to use an expected condition to force the code to wait before checking if the script is present:
WebDriverWait(browser, 3).until(EC.element_to_be_clickable((By.XPATH, "//script[#src='http://sample.com/file.js']")))
this might be happening because you're checking for the script before it gets loaded in the DOM, if this does not solve your problem, please update your question with an example of a URL that uses Google Tag Manager and doesn't load on selenium, as this will help identify the problem

Java code not executing after the Authentication popup appears on firefox[selenium webdriver]

I am trying to automate window authentication pop up handling.
Whenever I get a URL using driver.get(url) I gets a authentication pop-up.
I tried AutoIT scrip to automate authentication of popup which is working with internet explorer but not with firefox.
The code after the popup appears is not executing, so I think thats the reason AutoIT script is not working.
Code:
driver.get("xyz.com/"); // authentication pop-up appears after this line
Thread.sleep(3000);
System.out.println("done"); // This line is not executing.
try {
Runtime.getRuntime().exec(
"C://Users//basicauth_ff.exe");
} catch (Exception e) {
e.printStackTrace();
}
Script:
WinWaitActive("Authentication Required","","10")
If WinExists("Authentication Required") Then
Send("userid{TAB}")
Send("password{Enter}")
EndIf
By the sound of it it is a Firefox browser setting issue. You should either change your default settings for Firefox, or alternatively you can do it by setting preferences as follows:
FirefoxProfile fxProfile = new FirefoxProfile();
fxProfile.setPreference("item", value);
The documentation for it is here. https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/firefox/FirefoxProfile.html

Resources