0

I have an odd issue whereby I've loaded up a page in selenium webdriver using IE. My next step is to select an option (e.g.Reports) from the navigation bar at the top of the page. However, the issue when I do this is that I don't have the ability to select another option from the navigation bar. In fact when I hover over another option from the navigation bar to view the drop-downs attached to that, the browser tries to force me back to the original option.

It's an odd one....the page has loaded up fully, so that isn't the problem. Also when I load up the webpage outside of selenium, just using my IE browser locally, and repeating the steps manually, the issue does not occur. The code I'm executing is basic but I'll attach it anyway to see if it assists:

package Reports;

import org.openqa.selenium.ie.InternetExplorerDriver;
import IeDriverServer.iEServerMethods;

public class programMain {

public static void main(String[] args) {
    InternetExplorerDriver iedriver = iEServerMethods.IEOpenConnectingToExistingServer();
    iedriver.get("<my test url>");

    public static void terminatedReportCompletedPageLoad(InternetExplorerDriver driver)
    {
        driver.findElement(By.linkText("Reports")).click();                             
    }

  }

}

Any help would be appreciated as I am a bit stuck!

Andy

UPDATE - 18/11/14 Here is the code I am currently using

public static void terminatedReportCompletedFocus(InternetExplorerDriver driver)
{
    WebElement terminatedReportCompletedFocus = driver.findElement(By.xpath("html/body/div[1]/form/div[2]/div/ul/li[4]/ul/li[1]/ul/li[2]/a"));      
    Actions hoverOnReportWindow = new Actions(driver);
    hoverOnReportWindow.moveToElement(terminatedReportCompletedFocus).build().perform();
    terminatedReportCompletedFocus.click();
}
Andy Tilston
  • 227
  • 1
  • 5
  • 18
  • You probably need to use switchTo() and set focus on dropdown window. – Saifur Nov 17 '14 at 14:29
  • hi, thanks for this. Is the switchTo() done after the '.click' action? – Andy Tilston Nov 17 '14 at 14:32
  • You probably need to use `switchTo()` and set focus on dropdown window right before your click. But, at first you should take a look at `Select`(http://selenium.googlecode.com/svn/trunk/docs/api/java/index.html?overview-summary.html). Selecting option using `Select` more preferable. See here (http://stackoverflow.com/questions/12940592/selenium-webdriver-how-to-select-item-from-dropdown-list-using-selenium-webdri) for an example. **PREVIOUS COMMENT WAS INCOMPLETE** – Saifur Nov 17 '14 at 14:38
  • Hi Saifur, many thanks for your response......I think I'm almost there with it thanks to your advise. The issue I now have is that when I arrive at the page I want to (via the dropdown options) the focus remains on the option I selected from the dropdown to get there. How would I switch control over to the webpage I am on so that I can carry out any actions on that page? Would it be a 'switchTo()' again? – Andy Tilston Nov 17 '14 at 17:16
  • I assume you have multiple frame/window to perform multiple options. Selenium has multiple options to switch and set focus or frame or window. Read through (http://stackoverflow.com/questions/9942928/handling-iframe-in-webdriver). If you want to go back to default window you use something like this `driver.switchTo().defaultContent();` – Saifur Nov 17 '14 at 17:33
  • Hi Saifur, it's the same window but there is a parent drop down menu when I hover over the option from the navigation bar. When I hover over the parent drop-down, it displays a list of items for selection in a child drop-down.....I'm trying to click on one of these, to redirect me to a new page. It open's up in the same browser window, though. I was going to add an image but my reputation isn't high enough! :-) – Andy Tilston Nov 18 '14 at 09:20
  • am I right on saying that after the click even to arrive at the desired page, I should then do the 'driver.switchTo().defaultContent();' statement? Will this then free up the page for me to carry out any actions I require? – Andy Tilston Nov 18 '14 at 10:53
  • No default content should only be used to switch back to parent window – Saifur Nov 18 '14 at 14:02
  • Hi Saifur, thanks for the response. I've pasted in the code I have used, above entitled 'UPDATE - 18/11/14'. What recommendations would you make to switch focus back to the parent window? – Andy Tilston Nov 18 '14 at 14:13
  • It's really hard for me to suggest any solution without knowing about your application. However if the code above works and you are having problem to switch back to parent window then `driver.switchTo().defaultContent();` is enough. If a new window or tab opens after you performing these actions then you may need to do something like `Driver.SwitchTo().Window(Driver.WindowHandles.LastOrDefault());` (written in C#). Hope this helps – Saifur Nov 18 '14 at 14:27

0 Answers0