I have installed Enterprise mode on IE11 to support applications which are only run on lower version of IE.
Using Enterprise mode on, to support application adhered to IE10 only I started scripting.
I am successfully able to traverse few pages but at one particular sidebar I am not able to click element.
It gets highlighted using javascript which means I find the element. But I am not able to click the element. it gets dotted square around the element.
I don't get any exception on that line.
There are no frames issue.
P.S: One of the post stated that there might be an issue with unexceptional behaviour of Tomcat. Due to which I find element but click() event does not work.
Try:
element.sendKeys(Keys.ENTER);
If not working try:
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
Related
Tried to find xPath of an element in the latest Chrome (v99). It looks like the right-click menu in Chrome's "inspect" pane is not available. How does one find the xPath of elements for Selenium automation?
Chrome's Inspect menu item is still available after the right-click.
However, google-chrome latest version is Version 100.x which you need to upgrade to.
Having said that, some websites may disable the right-click for security or some other reasons. In those cases you have use the google-chrome-devtools to identify the desired elements.
You can find a relevant detailed discussion in How to inspect element for Selenium v3.6 as FireBug is not an option any more for FF 56?
I am testing a platform with Selenium and IE 11 Using IE Driver 3.0.0.
Windows 10 Pro
Java JDK 1.8.0_25
As for my research, I tried this:
String currentWindow = driver.getWindowHandle();
driver.switchTo().window(currentWindow);
And with JavaScript, I also tried this. (See first answer)
Is there any way I can bring the IE window that selenium opens and bring it to front/focus it? Since I use a robot at one point to perform a few actions, I need the browser to be on focus automatically, otherwise my robot actions are not effective.
((JavascriptExecutor) driver).executeScript("window.focus()");
I made some Automation tests with Selenium working on chrome, but now when I tried them in IE11 I got this weird behaviour: I land in a Page with a Search Box and a Search Button, pretty standard, and when I either set(" ") or sendKeys(" ") to an input textbox, the page "moves" to the left as is it had broken, imagine the page in the center of the screen and suddenly the left margin would dissapear and the page would stretch to the left... Does anybody know what I'm talking about?
Any help please?
BTW I also tried doing some actions in other elements and they won't break the page, also clicking the textbox won't do the trick, it happens when I put text in it
Well, "sendKeys" is likely what we call a "native event" and so it depends highly on the implementation of the binary driver for IE. For example, Selenium only officially supports native events on Firefox up to version 31.0.6 and not versions 32+. IE11 is pretty new and also comes in different versions (since it auto-updates). So, if you need to do a sendKeys that is non-native (which is usually not necessary) then you can probably code one using a JavascriptExecutor object. Let us know if that works for you.
-- addendum --
The Selenium team would tell you that they didn't want to include the javascriptExecutor funtionality in Selenium, but it is scenarios like this where the executor capability shows its true value.
I have written a script for datepicker to choose dates from the calendar. The scripts are running fine in local, but when I run it through jenkins the script is getting failed.
action.moveToElement(driver.findElement(By.xpath("//*[#id='ui-datepicker-div']/div[1]/div/a/span")));//locating the element to click
action.perform();
action.click(driver.findElement(By.xpath("//*[#id='ui-datepicker-div']/div[1]/div/a/span"))); //this line is not executing
action.perform();
The script to click the element is not working. I am getting error as "Element is not currently visible and so may not be interacted with"
I have also tried driver.findElement(By.xpath("//*[#id='ui-datepicker-div']/div[1]/div/a/span")).click() by replacing action.click() but still no use.
I have faced a similar issue and after a couple of frustrating hours, I have figured out, that im my case only one thing has worked for me - JavascriptExecutor.
I don't know why all other attempts have failed(all of them have worked well locally). It seems like Jenkins specific issues.
Anyway you can use this code snippet:
WebElement elem = driver.findElement(By.xpath("//path/to/element"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", elem);
Note: in my case I was always able to send click action to element, but somehow browser didn't react on this action. So element was remained unclicked without any error.
You cannot click on the hidden element using selenium because if will throw the exception that you saw. You should either make element visible (in the way the user does so) or use javascript to click (see JavaScript executor).
Clicking on an element works fine locally but not in Jenkins;
first, I was locating the web element using XPATH, and when it came to clicking I tried selenium click, actions click, js click. All were working locally But not in Jenkins.
Finally what worked for me was the combination of css selector with javascriptExecutor click. This solved my problem. Now works both locally and in Jenkins.
So try the same.
I'm using Selenium to navigate a webpage which has a link called "Mail", using WebDriver (just recently switched from RC to WebDriver). I want to click on the link but the testcase always fails with the error:
org.openqa.selenium.NoSuchElementException: Unable to locate element:
{"method":"link text","selector":"Mail"}
When inspecting the element with Firebug I get the following HTML:
Mail
This is the Java which attempts to click the link:
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.linkText("Mail"));
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
I can see that the element is present on screen but still, the test case fails.
Does anyone know what I might be missing here or an alternative way to find the link element?
Try via XPath. Example:
driver.findElement(By.xPath("/a[text()='Mail']"));
Would also be worthwhile double checking to ensure there are no iframes on the page.
Even i had faced this situation once. View your source code and find out if the element you are looking for is inside a frame. If yes, first switch to the frame in which the element is located and then look out for the element. It worked this way for me.
So far the best workaround I found for cases like this:
Open Firefox with Selenium IDE installed
In firefox open the test page
Run selenium IDE, start recording and click the link
Selenium IDE will offer you ways how to locate the target. If you switch to relative XPath, it should do the magic (Or, in my cases, it always helped)