0

I have an issue when attempting to click on an element from a drop-down menu, when running a test in Selenium. So, as per the below screenshot, I am hovering over 'Reports', then 'Asset Management', then 'Terminated Report: Pending'. Clicking on the 'Terminated Report: Pending' option should take me to the appropriate page Screenshot 1

I've written the following code in WebDriver to do this:

    public static void terminatedReportPendingFocus(InternetExplorerDriver driver)
{
    WebElement terminatedReportPendingFocus = driver.findElement(By.xpath("//a[contains(@href,'GetTerminatedPendingReport')]"));
    terminatedReportPendingFocus.click();
}

I didn't see any issues with this, given that I had used similar code in order to access the 'Terminated Report: Pending' page. However, for some reason when I run the test, whilst the browser initially focuses on the element I want, it then loses focus and drops down to the 'Collections' drop down and selects a page with a completely different href to the one I selected in the code. Can anyone help as to what the reason might be? Many thanks

ASSET MANAGEMENT IMPLEMENTATION

    public static void assetManagementFocus(InternetExplorerDriver driver)
{
    WebElement assetManagementFocus = driver.findElement(By.xpath(".//*[text()='Asset Management']"));
    Actions hoverOnReportWindow = new Actions(driver);
    hoverOnReportWindow.moveToElement(assetManagementFocus).build().perform();
    assetManagementFocus.click();
}

COMPLETE IMPLEMENTATION OF CODE

public class optionFocusControls {

//REPORTS TAB   
public static void reportWindowFocus(InternetExplorerDriver driver)
{
    WebElement reportWindowFocus = driver.findElement(By.linkText("Reports"));
    Actions hoverOnReportText = new Actions(driver);
    hoverOnReportText.moveToElement(reportWindowFocus).build().perform();           
}

public static void assetManagementFocus(InternetExplorerDriver driver)
{
    WebElement assetManagementFocus = driver.findElement(By.xpath(".//*[text()='Asset Management']"));
    Actions hoverOnReportWindow = new Actions(driver);
    hoverOnReportWindow.moveToElement(assetManagementFocus).build().perform();
    assetManagementFocus.click();
}

public static void daysInStockFocus(InternetExplorerDriver driver)
{
    WebElement daysInStockFocus = driver.findElement(By.xpath(".//*[text()='ET Days In Stock']"));
    Actions hoverOnDaysInStock = new Actions(driver);
    hoverOnDaysInStock.moveToElement(daysInStockFocus).build().perform();
    daysInStockFocus.click();
}

public static void terminatedReportCompletedFocus(InternetExplorerDriver driver)
{
    WebElement terminatedReportCompletedFocus = driver.findElement(By.xpath("//a[contains(@href,'GetTerminatedCompletedReport')]"));    
    terminatedReportCompletedFocus.click();
}

public static void terminatedReportPendingFocus(InternetExplorerDriver driver)
{
    WebElement terminatedReportPendingFocus = driver.findElement(By.xpath("//a[contains(@href,'GetTerminatedPendingReport')]"));
    terminatedReportPendingFocus.click();
}

}

FIX - 01/12/14

    public static void terminatedReportPendingFocus(InternetExplorerDriver driver)
{
    driver.findElement(By.xpath("//a[contains(text(),'Terminated Report: Completed')]")).sendKeys(Keys.ENTER);      
}
24
  • Can you provide the code of your implementation for the same? I am interested to known the element detection method for 'Asset Management'. Commented Nov 26, 2014 at 13:21
  • Hi Rupesh, thanks for replying. I've attached the implementation code above, entitled 'ASSET MANAGEMENT IMPLEMENTATION' Commented Nov 26, 2014 at 13:29
  • I have modified my code and included manual wait for 3 sec. please test and let me know Commented Nov 26, 2014 at 13:38
  • Great, thanks a lot. so I just need to add this manual wait for 3 seconds to the snippet of code I placed on my original note? THe Asset Management functionality was working ok, so do I not need to apply the wait command to that section of code? Commented Nov 26, 2014 at 14:06
  • Thats Wonderful..Would love if you make my answer as correct or Upvote it so that other users with the same problem may fix in the same way. Commented Nov 26, 2014 at 14:09

1 Answer 1

1

Try below code and let me know what happens

WebElement Reports = driver.findElement(By.xpath("--------//---As per your code"));
WebElement Asset Management = driver.findElement(By.xpath("--------//---As per your code"));
WebElement Terminated_Report_Pending = driver.findElement(By.xpath("--------//---As per your code"));
        Actions builder = new Actions(driver);
        builder.moveToElement(Reports).perform();
        Thread.sleep(3000);
        builder.moveToElement(Asset Management).perform();
        Terminated_Report_Pending.click();

Try below from in your code

public static void assetManagementFocus(InternetExplorerDriver driver)
{
    WebElement assetManagementFocus = driver.findElement(By.xpath(".//*[text()='Asset Management']"));
    Actions hoverOnReportWindow = new Actions(driver);
    hoverOnReportWindow.moveToElement(assetManagementFocus).build().perform();
    Thread.sleep(3000);
    assetManagementFocus.click();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.