Testing a frame based web application in Opera using Selenium 2 - opera

I am testing our frame based web application using Selenium 2. This is the simple code that tries to login a user, and on the resulting page switch to the frame with the content of the page:
driver.get("http://localhost/index.pl");
driver.findElement(By.name("session_username")).sendKeys("my_username");
driver.findElement(By.name("session_password")).sendKeys("my_password");
driver.findElement(By.xpath("//input[#value='log in']")).click();
driver.switchTo().frame("qabody_r_head");
This works correctly if I send in a WebDriver of type FirefoxDriver, InternetExplorerDriver or HtmlUnitDriver. But if the driver is of type OperaDriver I get an exception with the following error output.
Exception in thread "main" org.openqa.selenium.NoSuchFrameException: Invalid frame name qabody_r_head
Build info: version: '2.15.0', revision: '15105', time: '2011-12-08 09:57:28'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_02'
Driver info: driver.version: unknown
at com.opera.core.systems.scope.services.ums.EcmaScriptDebugger.changeRuntime(EcmaScriptDebugger.java:431)
at com.opera.core.systems.OperaDriver$OperaTargetLocator.frame(OperaDriver.java:772)
at SeleniumTest.testLogin(SeleniumTest.java:26)
at SeleniumTest.main(SeleniumTest.java:59)
Am I doing something wrong, or doesn't OperaDriver work with frames?

Is this frame directly inside the top page, or inside a sub-frame? If it is the latter, you may have to start at the top of the hierarchy and select parent frame first.
I've noticed issues when using Dragonfly/test tools with frames but I thought they were resolved. If you could put a small demo somewhere I could have a look..

I encountered the same situation when using the OperaDriver.
I wanted to switch to a frame contained in the main window. I was not able to switch to the frame, and instead I got the following error
org.openqa.selenium.NoSuchFrameException: Invalid frame name
Below are the steps I took when trying to select the frame:
//...
driver.switchTo().defaultContent();
driver.findElement(By.xpath("//input[#value='Save']")).click();
driver.switchTo().frame("SaveFrame");
//...
Note that the above code works perfectly in IE, Firefox and Chrome.
I used Opera 11.60 when testing the above.
I wasted a couple of hours and did not find an answer to this one.
Has someone worked with the switchTo().frame() method for Opera and it worked ?

Related

Wait required before Selenium-ChomeDriver/Chome can click element correctly (ChromeDriver v 77 & 78, Chome v 78)

As mentioned in the title, the following issue occurs since chrome was updated to v78. Before chrome v78 all tests worked just fine.
The behavior is highly nondeterministic, so please bear with me.
Meaning sometimes it just works out of a sudden, without any changes. Most of the clicks in the tests are working. Just some fail repeatedly (most of the time).
We are using selenium with the latest driver for chrome 78. The problem appeared first on driver version 77 with chrome 78 running.
Not the spec-flow tests nor the adapter-code has changed in any way, but after the Chrome update basically all tests failed.
Doing a Thread.Wait(1000) before EVERY CLICK seems to be the most reliable way to avoid the problem, and clicks the element as requested.
When im not waiting, the driver runs through the "Click", including the steps listed below, without actually clicking or throwing any error.
lookup of the element:
new WebDriverWait(this.webDriver, this.WaitTimeout).Until<IWebElement>(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(by))
waiting for the element to be clickable:
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(by));
scrolling towards the element:
((IJavaScriptExecutor) this.webDriver).ExecuteScript("window.scrollTo(0, " + (object) (e.Location.Y - 250) + ")");
and performing a click and release action on the element:
action.Click(element).Perform()
i have also tried several other variants of mouse clicks including the one from the comment.
Since the process just works through all this, without actually throwing an error or warning of any kind, i have no way of checking if the click actually happened (other than checking the current URL, which would be a nightmare to maintain in the tests).
So the website is not updating and remains on the source page and the test will fail because the next test doesn't run on the expected page.
now the question:
Is there anything i can query for or wait for to see whether the driver or chrome can actually click that element (really) or to verify that it was actually clicked?
original issue report:
https://github.com/jsakamoto/nupkg-selenium-webdriver-chromedriver/issues/66

how to locate element with selenium webdriver

After exporting a test in Visual Studio using Selenium webdriver, I execute the test case in VS and it fails when trying to locate an element in the test. The element is a tab within a page but the test case cannot find the id of the tab. This is the failing line driver.FindElement(By.Id("ui-id-14")).Click(); and I also tried to locate the element with the ClassName driver.FindElement(By.ClassName("ui-tabs-anchor")).Click(); by inspecting the element in Chrome browser but it still fails. Anyone can tell me what am I doing wrong here? Thank you in advance.
driver.FindElement(By.Id("ui-id-14")).Click();
driver.FindElement(By.ClassName("ui-tabs-anchor")).Click();
How Do you initalize you driver? A common mistake is not having a implicit wait with selenium. The driver tries to locate the element as soon as the document is ready, which is not feasible with "normal" JS applications as they are rendered after the document is ready. Try:
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
This way the driver will try to find the element every 0.5 seconds up to 30 seconds before throwing an Exception. By the way: Welcome to stackoverflow. Please consider posting your code/code snippets, that makes analysis often easier. My suggestion is purely made from my experience with people being new to Selenium.

issues in running selenium in internet explorer

Hi I am trying to run my selenium webdriver on IE9.
WebDriver version : 2.32.0
IE:9
IEDriverServer_win32:2.32.3
windows7
Below is my code:
File IEDriver=new File(System.getProperty("user.dir")+File.separator+"BrowserDrivers"+File.separator+"IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", IEDriver.getAbsolutePath());
DesiredCapabilities cap=DesiredCapabilities.internetExplorer();
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
WebDriver driver=new InternetExplorerDriver(cap);
driver.get("http://in00616:8421/GS");
Thread.sleep(3000);
//driver.findElement(By.id("j_username")).sendKeys("admin");
//driver.findElement(By.id("j_password")).sendKeys("admin");
driver.findElement(By.xpath(".//input[#id='j_username']")).sendKeys("admin");
driver.findElement(By.xpath(".//input[#id='j_password']")).sendKeys("admin");
driver.findElement(By.id("login")).submit();
Thread.sleep(2000);
driver.findElement(By.xpath(".//button[text()='Securities']")).click();
Thread.sleep(2000);
driver.findElement(By.xpath(".//span[text()='Issue']")).click();
Thread.sleep(2000);
driver.findElement(By.id("tabSecurities_Issue_Request_for_Issues")).click();
Above code logs in to my site but then when I try to click on Securities button I am not able to do it. Securities button starts flickering and then I am notified that unable to find the element.
Exception in thread "main" org.openqa.selenium.NoSuchElementException:
Unable to find element with xpath == .//span[text()='Issue Type']
(WARNING: The server did not provide any stacktrace information) –
Same code works fine in FireFox.
Please help as i am suppose to test my UI on InternetExplorer.
I think it is the version compatibility issue.
Can anyone suggest the compatible version set for IEDriverServer, Selenium WebDriver and IE which is in working condition.
As this SO answer points out, IE does not have native XPath support. Instead, Selenium WebDriver uses an old third party xpath library when IE is being used. Firefox has integrated support for XPath, which is why your selectors work fine in that browser.
I would highly recommend you update your selectors to instead use CSS selectors. They are supported across all browser, are easier to read, understand, and pick up, and they are pretty fast.
You can learn more about how to use CSS selectors from some different tuturials here, here, and here, and a CSS selectors cheatsheet.
Also, whenever possible, please try to not select an element by the text it contains. If you can select an element by its ID, class, other attribute, or even through the DOM chain (i.e. "div.1 > div.2 > span.a > a.b"), is better than trying to select an element by text.
Webdriver has difficulty with IE using locators. It seems like Murnal has difficulty using CSS locator. My advice would be you HAVE to use other locators if one doesnt work. This issue comes again and again while using non firefox browser. In the meantime an easier way to come up with alternate locator is use Firefox selenium IDE, there in the boxes where you type command you will see it gives alternate locator as well. Copy that and try plugging tha in your webdriver's findelement script.
Hi all i have found out that it was the issue of Selenium Webdriver 2.32 with IEDriver_Server2_32. After trying out permutation & Combination with latest available webdriver versions and IEDriver_Server, i have found out suitable stable configuration to work on IE9 below is the stable configuration : Webdriver : 2.33.0 IEDriver_Server : 2.33.0. There is still small issue but i am trying to look for workaround. Issue : In IE if some control's tooltip overlaps other control than IE is not able to find out that control. i guess this issue is with IEs working. IE uses nativeEvents to perform operation hence it is not able to locate that control. In FF it is able to find out that control and it is working fine. Thanks everyone.

Selenium: Can't SendKeys() to an item that was below the visible window but was made visible by Click()

I have this problem with a text field that is visible at the time of the SendKeys. I'm using IEDriverServer.exe and C#.
Here's how I can reproduce the problem:
The text field in question is visible in the window but you have to scroll down to see it. To scroll down I click on the element using code like this:
var element = driver.FindElement(By.Xpath("…"));
element.Click();
This scrolls the window down and makes the text field visible.
But when I try to send text to now-visible window:
element.SendKeys("blah");
I get the exception:
When_applicant_enters_application.Should_be_instantly_approved_on_external threw exception: OpenQA.Selenium.ElementNotVisibleException: Element is not displayed
How can I fix or workaround this problem?
Selenium version: 2.32.1
OS: Windows 7
Browser: IE
Browser version: 9.0.15
I've written code demonstrating the problem and submitted it to the Selenium tech support volunteers.
The full discussion is at http://code.google.com/p/selenium/issues/detail?id=5620
but the take-home is:
// Doesn't work
// driver = new InternetExplorerDriver();
// driver.Navigate().GoToUrl(#"D:\CGY\selenium\Bug5620\Bug5620\Bug5620.htm");
// Works
// driver = new FirefoxDriver();
// driver.Navigate().GoToUrl(#"D:\CGY\selenium\Bug5620\Bug5620\Bug5620.htm");
// Works
driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl(#"http://localhost:8080/Bug5620/"); // Hosted on Tomcat
so there may be a problem that possibly involves IE, IE security settings, Visual Studio local servers and/or the IE Driver. This may not even be a code problem, but something that needs to be documented, since other people are apparently running into the problem.
I don't know where the problem is exactly but I do have a work-around at this point, which is to use the Firefox Driver.
Thanks for your help, Jim. If you find out a better way of dealing with the problem, please add an answer here for the other folks.

IE is continously maximizing and minimizing when test suite executes

I'm using
Selenium standalone server - 2.25.0
IE - 8.0.7601.17514 (64 - bit edition)
IEDriverServer.exe - 2.28.0 (64-bit)
OS - Windows 7 professional
Java - SDK7
I'm using below code to launch IE and run a simple test.
WebDriver driver = null;
DesiredCapabilities ieCapabilities = null;
ieCapabilities = DesiredCapabilities.internetExplorer();
if (ieCapabilities != null) {
driver = new InternetExplorerDriver(ieCapabilities);
}
driver.get("http://www.yebhi.com/");
// driver.findElement(By.id("anchSighin")).click();
driver.findElement(By.xpath("//div/ul/li/a/div/span")).click();
driver.findElement(By.xpath("//div[80]/a")).click();
driver.findElement(By.xpath("//div[4]/div/div[2]/div/div[4]/a"))
.click();
Thread.sleep(5000);
driver.findElement(By.xpath("//div[5]/div[4]/div/div[4]/a")).click();
driver.switchTo().frame(2);
driver.findElement(By.id("txtMoblogin")).clear();
driver.findElement(By.id("txtMoblogin")).sendKeys("ghfghghf");
driver.findElement(By.id("txtMobPass")).clear();
driver.findElement(By.id("txtMobPass")).sendKeys("hfghgh");
Thread.sleep(5000);
driver.findElement(By.id("btnLogin")).click();
By using above code i was able to launch and run the test, but with a problem.
The actual problem is the browser is continuously maximizing and minimizing until the test suite get finished.
I am struggling with this issue for more than a week. I don't know weather it is a bug or not. If it is a bug please resolve me.
Thanks in advance.
The IE driver is resizing the IE window because you are taking screenshots. It WebDriver, screenshots are, by definition, of the full page. However, in order to take a screenshot of the full page without scrolling (which would screw up absolutely positioned elements), you have to be able to render the full page in IE. The only way to get the full page to render is to resize the IE window so that the full page is visible without scrolling. So, the IE driver does the resize automatically for the screenshot API call, then restores the window to the state it was in before the call.