File upload filename text overflows only during Selenium Webdriver session, blocking the upload button - selenium

During testing with Selenium + Chrome + Webdriver the filename chosen in a file input field overlaps the edge of the field, and covers the upload button so it cannot be clicked on.
The error I get in testing is valid and correct, as I cannot click on the button manually either:
Exception in thread "main" org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <button type="submit" id="article-file-upload-submit" class="ui primary button">...</button> is not clickable at point (427, 451). Other element would receive the click: <input type="file" name="import" id="article-file-upload-file" class="ui button" required="" data-qa-tag="project-file-import">
Why would viewing a page in a webdriver session change the rendering of a field?
This is what it normally looks like in Chrome:
This is what it looks like during testing in Chrome via webdriver:
(they are the same size in real life)
I am loading the same page here, in the same browser version, logged in as the same user, inside the same project and uploading the same file. The only difference I can see is the "bad one" is launched from Java, Selenium, Webdriver, from a VS Code project. So it is a different process.
Chrome Version 86.0.4240.80 (Official Build) (x86_64)
chromedriver v86
Mac OSX
The browser window isn't any narrower, (responsiveness doesn't affect this element).
I'm using the latest Semantic UI v2, the field is inside an accordion inside a segment, but in 2 years of dev evolution, I've never seen this overflow problem.
<div class="ui input">
<input type="file" name="import" id="article-file-upload-file" class="ui button" required>
</div>
<button type="submit" id="article-file-upload-submit" class="ui primary button">
<i class="icon upload"></i> UPLOAD
</button>

Click using javascript should work:
JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;
String script = "document.getElementById('article-file-upload-submit').click();";
javascriptExecutor.executeScript(script);

It turned out that the overlap issue was just a CSS bug in my latest app version, but for some reason it only showed up in the new web driver Chrome session.
A while later it showed up in the other Chrome window, so it was probably just a CSS caching issue. I've not seen this before though, as I am using a automated Gulp build with Browsersync which normally keeps everything up to date.
So it's nothing to do with webdriver, and in fact the test was finding a true bug, so it's good that it failed!

Related

Selenium WebDriver, works fine on laptop but not on desktop.WHY?

I'm using Selenium Webdriver latest version and run the test on Chrome v69.0.3497.100.
When I execute script in my laptop, It working fine and click on the element but on desktop, it find element but can't click.
This is HTML of element:
<div class='col-sm-1'>
<div style="position: relative;margin-top: 19px;left:14px;" class="material-switch">
<input id="checkHiddenDevice" name="checkHiddenDeviceOption" type="checkbox">
<input id="checkHiddenDevice" name="checkHiddenDeviceOption" type="checkbox">
<label for="checkHiddenDevice" class="label-primary">
::before
::after
</label>
</div>
</div>
This is the Xpath:
//div[#class='col-sm-1']
I've also tried some xpaths like //label[#for='checkHiddenDevice'] or find element by CSS but it doesn't work. only xpath //div[#class='col-sm-1'] is working but in laptop only.
Then I try on KatalonRecorder Tool. When I put my Xpath and run, test case passed because it finds element but didn't click? Then I try to find Xpath by Katalon tool then Katalon generate this Xpath:
xpath=(.//*[normalize-space(text()) and normalize-space(.)='#of devices'])[1]/following::label[1]
But with this xpath it also can't find element (or I don't know how to change it to right xpath in my code)
Does anyone was faced with such problem?
Yes.. Even i have faced this issue, this issue might occur when the browser zooming is more than 100%. just execute the same scripts with 90% of browser zoom

Click on element in robot framework is not working in ie and work fine in chrome and fiorefox

Click Element is not working in Robot Framework, in the log.html it shows that it clicked on the element, but it does not actually happen in the browser.
The element which I want to click is:
<a href="http://www.twitter.com/intent/tweet?text=Orange%20named%20a%20Top%20Employer%20Global%202018%20for%203rd%20consecutive%20year&url=http%3A%2F%2Fintegration-ruby.proj.620nm.com%2Fen%2Fblogs%2Forange-named-top-employer-global-2018-3rd-consecutive-year&via=orangebusiness" class="share-button-twitter" target="_blank" title="Share on twitter">
<span class="fa-lg fa-stack text_black"> <i class="fa fa-circle-thin fa-stack-2x"></i> <i class="fa fa-twitter fa-stack-1x"></i> </span>
</a>
I run my test using:
Execute JavaScript document.querySelector(".share-button-twitter").click()
Execute JavaScript document.querySelector('a[title="Share on twitter"]').click()
Execute JavaScript document.querySelector(".fa-lg fa-stack text_black").click()
Click Link //a[#title="Share on twitter"]
Click Element //i[#class="fa fa-twitter fa-stack-1x"]
Click Element //span[#class="fa-lg fa-stack text_black"]
The element is visible in the page, and the script works fine in Chrome and Firefox I find this issue with the browser IE.
What can be the reason for this? Any idea to solve the problem?
Update your Internet Explorer to the latest version. And also download the appropriate supported version of IEDriver for that version of IE. The problem is only here, and no where else.

Click button with oncick javascript not working in Selenium IDE

I have two buttons that are linked to a onclick javascript (see below)
<button
type="button"
class="ui-datepicker-current ui-state-default ui-priority-primary ui-corner-all"
onclick="DP_jQuery_1480511128847.datepicker._gotoToday('#historical-datepicker');"
>Current Month</button>
<button
type="button"
class="ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all"
onclick="DP_jQuery_1480511128847.datepicker._hideDatepicker();"
>DONE</button>
Clicking on DONE should update the page with new content. It does work normally but not with selenium IDE test.
Selenium find the correct button but it does not trigger the load of the new page.
All locators work when I click on Find: (see locators) :
xpath=(//button[#type='button'])[3]
//div[#id='ui-datepicker-div']/div[2]/button[2]
//button[2]
The div which contains the button is hidden at the start of the page. It is displayed by clicking on a field in the page.
Any ideas why the page does not load with selenium IDE?
Another thing, when I play the selenium IDE test, there is no error reported. And if I manually click in any part of the page, the new page loads.

Failed click using Selenium and XPath

For test automation on a web app I am currently using Robot framework and the Selenium library. There comes the moment I want to click on a button and then I wait for an element to appear. Alas, the click, although recorded successful in the log, does not lead to the apparition of the element I wish. In fact it is as if the click never happened.
To click on the button, I retrieve it using xpath. Using Firepath I successfully verified that the element is unique and does exist but what it shows leads me to think I have found why the button is not clicked correctly
You can see in light blue the button I want to click on and wrapped with dotted line the zone detected by firepath.
Is it possible that the click is done next to the button instead on it ?
Here is the incriminated line :
Click Element xpath=(.//button[contains(#id,'editContract')])[1
Edit :
HTML of the page :
<button id="listContractTableForm:listContractTable:0:editContract" name="listContractTableForm:listContractTable:0:editContract" type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" onclick="window.location.href='destinationPage?faces-redirect=true&contractEntityContractId=678'">
<span class="ui-button-icon-left ui-icon ui-c ui-icon-search"></span>
<span class="ui-button-text ui-c">ui-button</span>
</button>
Assuming you want the span with class containing ui-button-icon-left ui-icon ui-c ui-icon-search
//button[contains(#id,'listContractTableForm')]/span[contains(#class,'ui-icon-search')]
if you want the span with class="ui-button-text ui-c" simply change the class in the xpath

How to click on <input type=file> across browsers using Selenium Webdriver?

I'm working on dealing with a file-chooser dialog using Selenium 2 - WebDriver. Believe it or not, my problem is NOT dealing with the OS-native file-chooser. That part I can handle!
The problem is getting Selenium to properly click on the "Choose File" button. Since the original source html is simply <input type='file'>, the browser determines how to render it as a field and a button. As a result, the placement and naming of the button changes depending on browser. I've got it working in Chrome, but only because Chrome places the button on the leftmost alignment and Selenium happens to click there by default.
Any ideas? It's not clear to me if an input of this type is truly navigable from within the DOM anyway...
The proper way to upload a file on any OS is to
Find the <input type='file'> element. You need not to worry about different implementations and exact positioning. Just find the element for example by xpath //input[#type='file']
sendKeys() or type() (or whatever method writes text into elements in your language) the path to file to that input element.
Sample Java code:
// find the input element
WebElement elem = driver.findElement(By.xpath("//input[#type='file']"));
// 'type' the file location to it as it were a usual <input type='text' /> element
elem.sendKeys("C://path/To/File.jpg");
This works on every OS and browser in WebDriver.
Have exactly the same situation with element <input type='file'>. In my case it is created using ExtJS.
I don't know whether you have solved this question or not but let me provide my solution.
JavascriptExecutor executor = (JavascriptExecutor)getDriver();
executor.executeScript("arguments[0].click();", element);
Neither sendKeys() or type() nor using ActionBuilder was helpful for me. The only JavascriptExecutor works like a charm.
I tested with the following element:
<INPUT style="WIDTH: 550px; background-color:yellow" type="file">
Results:
IE: doubleclick on any area of the element, the "Choose File" dialogue would occur;
Firefox: click on any area of the element, the "Choose File" dialogue would occur.