Selenium IE driver not working with img element - java

I have this strange problem with img tags, my sample HTML code below
<html>
<input type='text' id='1111' MaxLength='10'/>
<img id='imageId001' title='hello' name='Done'/>
</html>
System.out.println(driver.findElement(By.id("imageId001")).getAttribute("title"));
Using Chrome Driver, getting output as hello.
However with IE 64/32 webdrivers,
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with id == imageId001(WARNING: The server did not provide any stacktrace information)
Whats wrong here???
Selenium WebDriver Version: 2.53.1.0
Internet Explorer : IE11
OS: Windows 7
JDK 1.7

After hours of effort spent, i figured out the cause. When i ran above code, i noticed a warning text displayed at bottom of IE as "Internet Explorer restricted this webpage from running scripts or ActiveX controls. " along with button "Allow blocked content". Since i have webdriverwait waiting for my img element, i clicked on this button and i saw that driver started printing the output which i was looking for (Same as chrome).
So i think driver object is not attached to browser if IE throws up some warnings like thsi. I solved it by disabling 2 options in Internet Options > Advanced Tab > Security section >
Allow active content from CDs to run on My Computer -> Set to Yes (ticked)
Allow active content to run in files on My Computer -> Set to Yes (ticked)
After this, my driver started identifying objects and works like chrome.
Note: Also i wanted to narrow down if registry setting played a role here as suggested by #Grasshopper. So I did same experiment in my colleague's machine (doesn't have registry settings for IE11) and this resolved for him as well. So registry setting does not play role here.

Related

Netbeans default browser doesn't start in Netbeans?

Scenario:
OS: Linux Debian 11
Kernel: 5.1.21
Browser: Mozilla Firefox 102.8.0esr
IDE: Netbeans 16
JDK: JAVA SE 19
Tomcat 10 (configured in netbeans)
In this scenario servlets run fine on tomcat writing URL on address bar. Trying to open the same URL with Browser in Netbeans fails because Browser doesn't come-up.
I perform following steps:
Single click on left button upon tomcat icon, then a Drop list come down with my Servlets
Right click Button on a Servlet (or tomcat main page), a second drop-list come down
Selecting "open in a Browser"
Browser doesn't start
Message info come-uo "Browser cannot Run): This message appears below in IDE netbeans and after few second vanished
I have also tried to compile index.html and as usual browser is expected to run, but in my case no! compiling process return no message error.
Looking for IDE Browser Configuration (TOOL>OPTION>GENERAL>EDIT) give me this set-up:
External Browser
Others browsers showed in the image above doesn't work. More-over next image shows IDE DEFAULT BROWSER without configuration. I tried to edit blank field but data were not saved after OK button click:
IDE DEFAULT BROWSER
I tried to edit blank field but data were not saved after OK button click. I have to admit that this last trouble is my fault because I blanked them and now re-edit it again is impossible.

How can I tell Selenium to press cancel on a print popup in Chrome 75?

I have been using the the suggested solution from : https://stackoverflow.com/a/41670021/4633408
And it worked perfectly since Chrome 71.
executor.executeScript("document.querySelector(\"print-preview-app\").shadowRoot.querySelector(\"print-preview-header\").shadowRoot.querySelector(\"paper-button.cancel-button\").click();");
But it no longer works.
Has anyone figured out a way to click, "Cancel" in the print preview for Chrome 75?
I caught the exception and it simply says:
e:org.openqa.selenium.WebDriverException: unknown error: Cannot read property 'shadowRoot' of null
Tested this on Version 75.0.3770.142 (Official Build) (64-bit) .They have additional element now
<print-preview-sidebar id="sidebar"></print-preview-sidebar>
For testing in console
document.querySelector("print-preview-app").shadowRoot.querySelector("print-preview-sidebar").shadowRoot.querySelector("print-preview-header").shadowRoot.querySelector("paper-button.cancel-button").click()
with executor.executeScript
executor.executeScript("document.querySelector(\"print-preview-app\").shadowRoot.querySelector(\"print-preview-sidebar\").shadowRoot.querySelector(\"print-preview-header\").shadowRoot.querySelector(\"paper-button.cancel-button\").click();")
EDIT :: For Version 79.0.3945.88 (Official Build) (64-bit)
document.querySelector("print-preview-app").shadowRoot.querySelector("print-preview-sidebar").shadowRoot.querySelector("print-preview-button-strip").shadowRoot.querySelector("cr-button.cancel-button").click()
In Chrome 77 the html elements of print dialog have changed again.
And changed again in Chrome 78.
Very annoying when on our jenkins the version is a few numbers behind the latest on my laptop. (I hope they soon enable that jenkins for docker containers)
For Chrome 78.0.3904.70:
testing in console:
document.querySelector("print-preview-app").shadowRoot.querySelector("print-preview-sidebar").shadowRoot.querySelector("print-preview-button-strip").shadowRoot.querySelector("cr-button.cancel-button").click()
executor.executeScript:
executor.executeScript("document.querySelector(\"print-preview-app\").shadowRoot.querySelector(\"print-preview-sidebar\").shadowRoot.querySelector(\"print-preview-button-strip\").shadowRoot.querySelector(\"cr-button.cancel-button\").click();");
Running this code before print popup :
executor.executeScript("window.print = function(){ return false;};");

Firefox Gecko driver cannot click on input element with type "file"

I am automating a page with two file upload buttons across all browsers. Here is the code snippet:
WebElement thumbnailClick = driver.findElement(By.id("PageForm_tile_src"));
jse.executeScript("scroll(0, 250)");
thumbnailClick.click();
This is the click on the first upload button, and this works perfectly in Chrome, but trying to run on Firefox gecko driver throws an InvalidArgumentException: Cannot click <input type=file> elements error
I have to find these elements by id since there are multiple upload buttons on this page. Why would firefox reject this click when it is easy to do manually and works on any other browser?
Adding HTML of element:
<input name="PageForm[tile_src]" id="PageForm_tile_src" type="file">
Firefox (via geckodriver) is behaving correctly here and Chrome is not. The W3C WebDriver Specification, in its description of the Element Click algorithm in Section 14.1, step 3 states: “If the element is an input element in the file upload state1 return error with error code invalid argument.”
When the Chromium team completes spec-compliance for chromedriver, it will behave as geckodriver, IEDriverServer.exe, the current preview version of Microsoft’s driver implementation for Edge, and Apple’s just released driver implementation for Safari 12 all behave.
To successfully upload files using WebDriver, you should use the sendKeys method with the full path to the file you want to upload.
1Ed. note: ”In the file upload state” is spec-language for an <input type="file"> element.

Open firefox devtools programmatically with FirefoxProfile

How can I launch Firefox 52 with opened devtools using selenium and Java?
Before the merge of Firebug into the Firefox DevTools I used FirefoxProfile to open the console programmatically:
profile.setPreference("extensions.firebug.console.enableSites", true);
etc.
But Firebug does not work anymore now.
So what is the proper way to launch with opened network or console tab?
And also, is there any analog extension to FirePath to launch automatically and use instead of the currently broken FirePath extension?
I managed to launch Firefox with given page and native devtools open from command line using -devtools parameter:
firefox -no-remote -profile "c:\deleteme" -devtools -url "http://example.com/"
It seems to be possible to pass that parameter to the WebDriver by calling
addCommandLineOptions("-devtools") on the FirefoxBinary instance.
(Via How can I tell selenium to start firefox with certain commandline options?.)
Or in Node perhaps by firefox.Options().setBinary(…).addArguments("-devtools")
Spotted the parameter in firefox -help | more, but alas, seems that not all information presented there as well as info given at Command_Line_Options MDC page are still valid. The -devtools one is missing at the MDN page at this moment.

To run tests on different browsers using Selenium webdriver+ TestNG+Java

I am trying to run my tests using Selenium web driver + TestNG + Java, everything runs fine with Firefox, but when I tried to extend it to different browsers like IE and Chrome, I have included code for it, but it doesn't seem to work. I am using some excel files to pass input while automating it. Thanks in advance
Required Configuration with IE
1.The IEDriverServer exectuable must be downloaded and placed in your PATH.
2.On IE 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone. To set the Protected Mode settings, choose "Internet Options..." from the Tools menu, and click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled "Enable Protected Mode".
3.The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates.
Check if java plugin is installed in your browser.
For more info go to http://code.google.com/p/selenium/wiki/InternetExplorerDriver
You cannot work with chrome/IE same as Firefox. In order to work with that you need chrome/IE driver, which is an executive file. The code for invoking the chrome and IE is a little different than Firefox.
For chrome you can take help from here
For IE you can take help from here
example for invoking driver
if(BrowserName.equalsIgnoreCase("Firefox")){
driver = new FirefoxDriver();
}else if(BrowserName.equalsIgnoreCase("Chrome")){
String ChromeDriverPath= "D:\\ChromeDriver\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", ChromeDriverPath);
driver=new ChromeDriver();
}else if(BrowserName.equalsIgnoreCase("IE")){
IEDriverPath32bit= "D:\\IEDriver\\IEDriverServer.exe";
System.setProperty("webdriver.ie.driver", IEDriverPath32bit);

Categories