I been trying to solve this issue but not sure what's the cause for this,
i made a program with java and phantomjs, and in theory they both should behave the same way.
Phantomjs in both the pc and the server is the same v.2.0.
In windows(v.7) mi testing program works as expected, but in linux (debian) the program fails, with this error when it tries to click an element:
Caused by: org.openqa.selenium.NoSuchElementException: {"errorMessage":"Unable to find element with css selector
Now, i know sometimes we have to wait for few seconds for the page to load, which already do (even added a few more just to be sure) and it was tested correctly in windows.
i tried with the click function:
element.click();
with a javascript code:
JavascriptExecutor js = (JavascriptExecutor)driver;
js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", element)
and with actions too:
Actions action = new Actions(driver);
action.moveToElement(element).contextClick().build().perform();
//and this code too
action.moveToElement(element).click().build().perform();
Anyone had this same or similar issue? what i else i can do? i'm stuck since yesterday and i wan't able to figure out this problem.
note: for now i have an alternate way to get page without having interaction, but still having different results from the web page when executing in different OS, for example:
where i normally i get this link: www.somesite.com/?search=xxxxx&date_in=dd/MM/yyyy¶ms=etc. , instead i get www.somesite.com/?search=xxxxx, the default search without any especific search parameters.
You need to use onResourceError callback, to find out what's going wrong.
You also need to use the following Command-Line options:
--ignore-ssl-errors=true --ssl-protocol=any --debug=true
See also: this issue.
Related
I'm trying to do a test that involves browser zooming in Selenium (Java). The following was my approach:
WebElement html = m_webDriver.findElement(By.tagName("html"));
html.sendKeys(Keys.chord(Keys.CONTROL, Keys.ADD));
This worked fine in IE, but causes an exception in Chrome saying "cannot focus element", which happens whenever I attempt to send any keys in Chrome.
The following sources have also had similar issues, but no workaround listed works for me:
https://sqa.stackexchange.com/questions/2023/webdriver-api-failed-to-send-keys-because-cannot-focus-element-better-work
https://code.google.com/p/selenium/issues/detail?id=2328&noredir=1
Thanks!
I'm not 100% sure, but it is probably best to use JavaScript for that.
Something along the lines of:
driver.executeScript("document.body.style.zoom=1.0"); // or 0.9 or whatever
While I am executing testcases (Selenium WebDriver + Java) on Internet explorer i am getting exception "unhandledAlertException" and testcases getting failed while it's working fine with Chrome and Firefox browser. Also having issue like: sometimes it click on element and respond accordingly and sometimes its clicked but did not respond with same code.
Here is some code from where it was throwing "unhandledAlertException"
protected void clickOnElement(WebElement element)
{
if(isElementPresent(element))
{
if(getBrowserName().equalsIgnoreCase("internet explorer")){
element.sendKeys(Keys.ENTER);
wait(2000);
System.out.println("In IE clicked on element");
}else{
element.click();
}
implicitWait(Integer.parseInt(ConfigParser.getProperty("common_wait_timeout")));
}
}
unhandledAlertException is now resolved by removing implicit wait from code. but sometimes unresponsiveness of elements in IE is still persist.
How can overcome from such issues with IE
Try adding proper wait conditinos in your code for IE browser. Generally IE doesnt respond well. Also have a look at the element Id's in IE they might be changing.
IE will always have issues with selenium webdriver. Microsoft itself doesn't maintain IE driver for selenium like chrome and FF. You best chances are to use proper wait.
What version of IE are you using? There are known issues with the latest versions of IE with Selemium. I faced similar issues and had to switch back to IE8. Also are you getting the exception after the browser is launched? Tip: Under IE options, make sure all the modes are enabled under the security tab and the zoom is set to 100%.
Hope this helps.. good luck!!
if (browser.equalsIgnoreCase(IE)) {
System.setProperty("webdriver.ie.driver", getRootDir() + "/src/main/java/configuration/IEDriverServer.exe");
driver = new InternetExplorerDriver();
you have to download IEDriverServer.exe and set the path in the above, and then get the driver of IE, it will work fine and i hope you will get any problem if it is even IE 11/click problem.
I have a code in selenium which dynamically clicks on the tabs in menu page. And sometimes happens that tab is not clickable(it is just a plain td with span inside) and when Web Driver tries to click on this tab, my program gets frozen (no exception thrown or anything).
I can't avoid clicking on tabs like that but I would like to somehow prevent that freeze after click. So can I set some timeout or tell to selenium what to do if element is not clickable?
driver.findElement(By.xpath(
format("//span[#class='rf-tab-lbl'][text()='{0}']",
navigation.getGroup()))).click();
//if the tab is currently selected (hence is not clickable) selenium won't click
// on it and program freezes
Please try another page from a different website. It might be a JS looping issue.
I encountered such an issue in HtmlUnit for some URLs.
I raised issue in HtmlUnit user group.
They told me that JS infinite loop was causing freez.
Time out did not work for me as well.
I tried to apply my own time out. That did not work too.
Refer following question for applying own timeout
HtmlUnit WebClient Timeout
If it works for another website, problem might be site specific.
You can attach source of Selenium in eclipse and check / debug where it is getting stuck.
I did same for HtmlUnit. I reached to parse method, which did not come out.
If still does not work, contact Selenium support.
I have a simple CSS-based dropdown menu, and I'm trying to click on one of the menu items in a Java Selenium (WebDriver) test.
Both the menu (<ul> element) and the items (<a>) have IDs and creating corresponding WebElement objects works fine. I'm trying to click on one of the items with code like:
hoverOver(transfersMenu);
transferLink.click();
In hoverOver(), I've tried all three answers from this question, but none of them work. I keep getting:
org.openqa.selenium.ElementNotVisibleException:
Element is not currently visible and so may not be interacted with
Command duration or timeout: 2.06 seconds
(I've tried calling transferLink.click() also before hoverOver(), in the hope that the implicit wait would make it work, but nope.)
Any idea how to make the hovering work so that the link can be clicked?
Selenium version 2.21.0. I'm running the tests on Linux (Ubuntu), using Firefox 13.0. A colleague just tried on Windows (using Firefox 12.0), and it didn't work for him either.
Update: As per Slanec's tip in comments, and these instructions, I tried setEnableNativeEvents(true) on the FirefoxProfile. At first this failed:
org.openqa.selenium.InvalidElementStateException:
Cannot perform native interaction: Could not load native events component.
...but after I upgraded to Selenium 2.23.1, I no longer get that complaint.
Still, the hovering doesn't work (with native events on or off). :-/
I use the following code to hover over our menus for 1 second, before clicking a link, just like the one you are using:
action = new SeleniumActionHelper(driver);
WebElement currentUser = findElementByLinkText("testing1");
action.mouseHover(currentUser);
Thread.sleep(1000);
Of note, the mouse cursor needs to remain in the browser window for the hover to keep. If the mouse cursor is outside of the browser window, I experience a quick flash of the menu, but it does not stay visible
Try this exampale:
WebElement menuHoverLink= driver.findElement(By.id("test"));
actions.moveToElement(menuHoverLink).perform();
driver.findElement(By.id("test")).click();
Thread.sleep(6000);
How do you run your test classes? I found out that running WebDriver through ANT makes hover actions impossible, whereas running the test classes from command line (TestNG JAR) or from Eclipse works just fine.
I get this error while running selenium RC tests against IE7.
com.thoughtworks.selenium.SeleniumException: ERROR: There was an unexpected Alert! [error:[object Error]]
It happens whenever I attempt to click a link or a tab or anything clickable. Any Ideas guys. This is really frustrating.
Checking the Google search results for your error message, and the selenium development mailing list, it sounds as if this is not a bug in Selenium but rather it is Selenium telling you that an unexpected window.alert() function was called in your web application, and that Selenium does not know how to handle it because you did not tell it how to.
I'd be surprised if the same issue isn't occurring in other browsers. Perhaps your application behaves differently depending on the browser? Basically Selenium is reporting that it can't move onto further commands after you are clicking on these links or tabs because it has detected an unexpected JavaScript alert. You wont see these alerts because Selenium consumes them. There are a few things you can do to work out what's going on.
The first thing I'd suggest is to just check your application in IE7. Manually complete the steps of your tests - do you see the JavaScript alerts? If so, you will need to add the appropriate commands to your Selenium test.
If for some reason you can't replicate the alerts manually you can either dismiss the alert by using the the getAlert command, or use the response from getAlert to find out the text of the unexpected alert.
Java/TestNG example for finding out the message of the alert:
assertEquals(selenium.getAlert(), "Hello World");
The above will still cause your test to fail (unless the alert really does say 'Hello World'), but will fail with a message similar to "expected 'Hello World' but was 'Your unexpected alert message'".
I'm getting a similar thing.
No error in IE, JS error popup in Chrome, nothing in FF...until I run my Selenium script and it reports an unexpected error.
Amusingly when I do selenium.IsAlertPresent() it returns false, even though it says there was one.
I'm seeing the same error. Normally we run our test using C#, but in this case we are setting up some simple tests using the Selenium IDE.
Since Selenium IDE records your events and then allows you to play them back you would expect it to handle the alert. When looking at the events it records it appears it's capturing the alert. However, when you play it back the events are out of order.
First it captures the click event. Then is uses assertAlert to make sure the alert happened.
The problem occurs when you play it back. It does the click event and then errors out. If you move the assertAlert statement before the click event it doesn't work. If you change the assertAlert to waitForAlert that doesn't work either. I can't seem to figure out anyway to get the playback working in the Selenium IDE. If I didn't need this runnable for a non-techy I'd just put it into my regular tests and be done with it.
Edit: After further review it appears the alert message isn't matching. Even though it grabbed the alert itself when doing the record. Visual inspection doesn't do anything to help me determine what it considers different.
I've seen this error also. In my case the issue was the latency in an Ajax response object was causing Selenium IDE error. The solution that worked for me was to add a pause command right after any Ajax calls in the test script.
The call below was taking few seconds to return with valid Ajax response
click
css=#form3 > div.addButton > button.btn.btn-primary
By adding a pause clause, the "Unexpected alert" issue was resolved
pause
5000
I Suggest you to test manually those steps which are there in your selenium test.If it is not reproducible then it might not be the problem in the page.
please debug your selenium script with assert function for identifying where is it finding the unexpected alert.
if (selenium.isAlertPresent()) {
assertEquals(selenium.getAlert(), "Hello World");
}
which will help you identify the problem. I suggest you to repeat the test because you may find that assertion occurring in different part of your code.