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
Related
Below is the HTML snippet I am trying to get xpath. I have tried so many combination in chrome dev tools but no luck. Chropath message is that element might be from different src.
I am not sure what it means. Any help appreciated.
<input type="text" class="sn-global-typeahead-input -global-active-input" name="sncwsgs-
typeahead-input" id="sncwsgs-typeahead-input" placeholder="Search Global" autocomplete="off"
aria-label="Search" aria-hidden="false" aria-expanded="true" aria-activedescendant="sncwsgs-
typeahead-record-1-2" aria-autocomplete="both" aria-owns="sncwsgs-typeahead-sections" aria-
controls="sncwsgs-typeahead-sections" aria-describedby="sncwsgs-typeahead-instructions" aria-
haspopup="listbox" value="" role="combobox">
There's an id tag, so you can use the following for the XPath:
"//input[#id='sncwsgs-typeahead-input']"
That also translates to the following CSS Selector:
"input#sncwsgs-typeahead-input"
But if that's inside an iframe, you'll need to switch to the iframe first before you can interact with elements inside of it.
Learn about switching into iframes here: https://www.selenium.dev/documentation/webdriver/interactions/frames/
Example of switching into an iframe:
driver.switch_to.frame("iframe")
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!
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.
In my testcase i have the next locater:
Double Click Element //input[#value='user1']
The locater is for the next snippet:
<tr onselectstart="listview_onselectstart(this, event)" tabindex="1" class="row altrow selected"><input class="text" type="text" tabindex="-1" readonly="readonly" style="width:;" value="user1">
This works perfect with Chrome and Firefox. When i try this with ie i see the page refresing and nothing happends.
Doesnt ie works with javascript ? Or what can be the problem ?
IE has a long-standing history of extremely poor performance when it comes to XPath selectors.
Please consider using CSS selectors if you intend to work with IE.
In your case, Double Click Element css=input[value=user1] should do the trick.
I am a newbie to java and selenium webdriver. I am having an issue clicking an image. Below is the page source.
<a href="javascript:void(0);">
<span class="HomeButton" onclick="javascript:onBtnHomeClick();"/>
</a>
I tried below codes but did not work and still getting the Unable to locate element error.
driver.findElement(By.xpath("//a[#onclick='onBtnHomeClick()']")).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[#id='js_AppContainer']/div[2]/div[1]/div[1]/span"))).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("HomeButton"))).click();
I have to click the homebutton. Any help would be much appreciated
I don't know why By.className("HomeButton") didn't work but you have errors in the other two.
In driver.findElement(By.xpath("//a[#onclick='onBtnHomeClick()']")).click(); the tag for onclick is <span> not <a>. It also not onBtnHomeClick() but javascript:onBtnHomeClick();
driver.findElement(By.xpath("//span[#onclick='javascript:onBtnHomeClick();']")).click();
If you want to use onBtnHomeClick() use contains
driver.findElement(By.xpath("//span[contains(#onclick, 'onBtnHomeClick')]")).click();
Or
driver.findElement(By.cssSelector("onclick*='onBtnHomeClick'")).click();
And in wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[#id='js_AppContainer']/div[2]/div[1]/div[1]/span"))).click(); the <span> parent tag is <a>, not <div>
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[#id='js_AppContainer']/div[2]/div[1]/div[1]/a/span"))).click();
You simply need the correct locator IF your element will be eventually visible.
Xpath = "//span[contains(#class,'HomeButton') and contains(#onclick,'onBtnHomeClick')]"
Add wait as needed above exanmple, that should work.