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

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.

Related

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

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!

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

span inside a button tag not clickable using selenium webdriver?

I'm trying to click and "Add Course" labelled button using selenium webdriver but it is not working out for me.
Here's the snippet I took from chrome developer tools:
<button type="button" class="btn btn-green" onclick="javascript:AddCourse();">
<span class="glyphicon glyphicon-plus-sign">
::before
</span>
<span translate="portallang_addCourse" class="open-sans ng-scope">
"Add Course"
</span>
</button>
You need one of the following xpaths:
First choice:
//span[contains(text(), 'Add Course')]
These two, only if there are always 2 spans and the second span is always Add Course:
(//button[#class='btn btn-green']/span)[2]
//button[#class='btn btn-green']/span[2]
Slowest option as the entire document is scanned. Add Course can only occur once on the page:
//*[contains(text(), 'Add Course')]
What error are you getting? What property did you use to click on the span element?
You got to use xpath for such elements.
Use xPath Finder add-on for Chrome and extract the unique xpath for this element:
https://chrome.google.com/webstore/detail/xpath-helper/hgimnogjllphhhkhlmebbmlgjoejdpjl?hl=en
You can always write an unique xpath manually but this just saves time and is accurate.
Hope this helps!

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

Selenium webdriver script that runs in IE hangs in Firefox

I have used selenium RC in the past but I am new to webdriver.
I have three links in my app. Notifications, messages and connections.
On clicking notifications, notifications drop box is displayed. On clicking messages, messages drop box is displayed and on clicking connections, connections drop box is displayed.
In the script, I click notifications link, wait for notifications drop box and then assert for notifications dropbox. Same for messages and connections in sequence.
The notification sequence works correctly. In messages, it clicks on messages link and then hangs on the wait for messages drop box link. I know this since I had put print command after every line.
Heres is my code:
driver.findElement(By.xpath("//a[#id='notifications-page-button']")).sendKeys("\n");
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[#id='notifications-dropdown-list']//li//div[#class='message']")));
Assert.assertTrue(isElementPresent(By.xpath("//div[#id='notifications-dropdown-list']//li//div[#class='message']")), "Notifications drop box was not displayed");
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//a[#id='messages-page-button']")));
driver.findElement(By.xpath("//a[#id='messages-page-button']")).sendKeys("\n");
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[#class='sf_messages_list dropdown']//li//div[#class='message']"))); //This is the line where the script hangs. If I remove this line and the next line and continue with just the click commands, they work. But when I have this line and the next, the remaining click commands are not executed
Assert.assertTrue(isElementPresent(By.xpath("//div[#class='sf_messages_list dropdown']//li//div[#class='message']")), "Messages drop box was not displayed");
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("connections-page-button")));
driver.findElement(By.id("connections-page-button")).click()
Heres the HTML for messages section:
<li class="icon mm open">
<a id="messages-page-button" class="mm" href="#">
<span class="icon"></span>
<span class="badge hidden_elem">
<strong>
<em>0</em>
</strong>
</span>
</a>
<div class="dropdown-holder">
<div class="sf_messages_list dropdown" data-eventprefix="mainmenu_messages">
<div class="tb-dropdown-header">Messages</div>
<div class="tb-dropdown-body" data-url="/messages/dropdown">
<div class="document-title" style="display: none; !important"> - Dropdown Messages</div>
<div id="messages_list_view_76345" class="message-threads-listview">
<ul>
<div class="no_items hidden_elem">
</div>
</div>
<div class="tb-dropdown-footer" style="display: block;">
</div>
<span class="shadow-hide"></span>
</div>
</li>
Heres the HTML for notifications section:
<li class="icon mm">
<a id="notifications-page-button" class="mm" href="#">
<span class="icon"></span>
<span class="badge hidden_elem">
<strong>
<em>0</em>
</strong>
</span>
</a>
<div class="dropdown-holder">
<div id="notifications-dropdown-list" class="sf_notifications_list dropdown" data-eventprefix="mainmenu_notifications">
<div class="tb-dropdown-header">Notifications</div>
<div class="tb-dropdown-body" data-url="/notifications/dropdown"></div>
<div class="tb-dropdown-footer">
<a class="view_all" href="/notifications/view">View All Notifications</a>
</div>
</div>
<span class="shadow-hide"></span>
</div>
</li>
The above code works on IE. So looks like the problem is not that it is not able to find the element.
I am using Selenium 2.25.0. I have tried various versions of FF including 3.6, 7, 11, 13, 15 and 16. But none of them worked.
Also, the script just hangs. It does not even throw an error in eclipse. I had once let my script run for around 11 hours and still no error.
Please let me know in case you need further information to help me resolve this issue.
Thanks!
Something similar happened to me in previous versions of Selenium Webdriver. And I was also clueless, whats happening to me. Eventually, updating to newest version of Selenium helped me for good, but because 2.25.0 is the latest, I will at least present you the workaround I was using until update solved it
Whenever I needed to click a button, nothing happened (as to you). So the workaround was, that when clicking button, I also send Enter key event to it.
To be more specific:
WebElement buttonWhereClickingDoesNotWork = driver.findElement(By.id("messages-page-button");
buttonWhereClickingDoesNotWork.click();
buttonWhereClickingDoesNotWork.sendKeys(Keys.ENTER);
Yes, its workaround. Yes, its not nice. And yes, it did help me.
And also: No, I do not know the root cause of this, since update of Selenium helped me in my case...
This seems to have some connection with a Facebook Login. Are you correctly switching between window handles? Also what is your implicit time out, by default it is set at 30 seconds, so I am not sure if your script can run for 11 hours without erroring out.
Can you try these
1) I am guessing, className("message") does not exist, and your script is actually getting stuck at that step and not the step after. Which involves the click.
driver.findElement(By.id("notifications-page-button")).click();
wait.until(driver.findElement(By.id("messages-page-button")));#<<-- Changed the element to wait for
//The code works untill here. But on the next command that clicks messages link, it hangs
driver.findElement(By.id("messages-page-button")).click();
wait.until(ExpectedConditions.presenceOfElementLocated(By.className(("username"))));
2) Remove that wait for element
driver.findElement(By.id("notifications-page-button")).click();
#removed this wait for element
//The code works untill here. But on the next command that clicks messages link, it hangs
driver.findElement(By.id("messages-page-button")).click();
wait.until(ExpectedConditions.presenceOfElementLocated(By.className(("username"))));
UPDATE
Please try this ...
driver.findElement(By.id("notifications-page-button")).click();
wait.until(ExpectedConditions.presenceOfElementLocated(By.className(("message"))));
//The code works untill here. But on the next command that clicks messages link, it hangs
driver.findElement(By.id("messages-page-button")).click();
wait.until(driver.findElement(By.id("connections-page-button"))); # changed it to wait for the element that you will next work with
driver.findElement(By.id("connections-page-button")).click();
wait.until(ExpectedConditions.presenceOfElementLocated(By.className(("connections-listview"))));
Also, if your provide an HTML snippet of the web elements, which you are not sure abt the locator, we can help figure it out.