0

My test script are developed using Java with Selenium webdriver api. There is 1 particular scenario where I need to click on a sub option loaded from a dropdown menu but I am not able to do that. Following are the test steps and the screenshot for the particular problem.

-Launch Microsoft Outlook Web App (OWA) and login

-On main screen I need to enter some text in Search Field

-Click the drop down next to it

-Select "This Folder" from the options loaded (Screenshot)

I dont see any frameid so not using any. Dropdown works fine but failing to click on suboption.

Adding the code which I am using for click this

public static final By searchDropDown_locator= By.xpath(".//*[@id='divSScp']");
public static final By thisFolderText_locator= By.xpath("(.//*[@id='spnT' and text()='This Folder'])[2]");


public void clickSearchDropDown()
{
    WebElement searchIcon= websitedriver.findElement(searchDropDown_locator);
    searchIcon.click(); 
}

public void clickThisFolder()
{
    WebElement searchIcon= websitedriver.findElement(thisFolderText_locator);
    searchIcon.click(); 
}

I am calling both these functions in my script file.

What could be the solution here.

Irf
  • 41
  • 1
  • 4
  • 9
  • @lrf - This question is much tougher to answer when you don't post the code that you have. – Brian Feb 02 '16 at 18:49
  • @lrf - Is `XPath` your only option for finding the 'This Folder' selector? – Brian Feb 02 '16 at 19:03
  • @Brian Yes. We are using xpath to identify the screen elements. What other option you are suggesting. – Irf Feb 02 '16 at 19:10
  • @lrf - Well, there are quite a few to choose from like, `name`, `className`, `id`, `cssSelector`. Finding by `XPath` can be unreliable and cumbersome. Do you have the option to use one of the others I suggested? – Brian Feb 02 '16 at 19:11
  • @Brian In current situation I would try other options till I get solution with xpath. – Irf Feb 02 '16 at 19:15
  • @lrf - See, this [answer](http://stackoverflow.com/questions/11777694/which-is-the-best-and-fastest-way-to-find-the-element-using-webdriver-by-xpath). – Brian Feb 02 '16 at 20:10
  • @Brian Finding xpath is not a problem, I have the correct xpath for this element. The problem is, it is not clicking. Something I am not doing correctly which I want to find. I tried using id but same result it is failing to click. – Irf Feb 02 '16 at 20:26
  • @lrf - Try: `WebElement searchIcon= websitedriver.findElement(thisFolderText_locator).click();` instead. – Brian Feb 02 '16 at 20:27

1 Answers1

0

Try to use JavascriptExecutor for click as below

public void clickSearchDropDown()
{
    WebElement searchIcon= websitedriver.findElement(searchDropDown_locator);
    JavascriptExecutor executor = (JavascriptExecutor) driver;
    executor.executeScript("arguments[0].click();", searchIcon);
}

public void clickThisFolder()
{
    WebElement searchIcon= websitedriver.findElement(thisFolderText_locator);
    JavascriptExecutor executor = (JavascriptExecutor) driver;
    executor.executeScript("arguments[0].click();", searchIcon);
}

Hope it will help you :)

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125