Selenium Click() on a particular element not working on Firefox and Works fine on Chrome

53 views
Skip to first unread message

Nagendra Kuppala

unread,
Feb 11, 2019, 12:36:38 PM2/11/19
to Selenium Users
Hi guys,

For some reason I'm getting a weird issue while clicking on a button element.

HTML code as below:
<button type="submit" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"><span class="ui-button-text">Search</span></button>

My code works fine in Chrome browser and having an issue with Firefox browser. Although the console output shows the Element is clicked, but I do not see that reflect in the application while automating causing the test fail.

public String clickAt(String identifier) {
 currentKeywordLog
= " Click on element: " +identifier;
 APP_LOGS
.debug(" Click on element: " +identifier);
 
try {
     
Actions action = new Actions(driver);
     
WebElement webElement = objectLocator(identifier);
     
Thread.sleep(800);
     
String scrollElementIntoMiddle = "var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);"
                   
+ "var elementTop = arguments[0].getBoundingClientRect().top;"
                   
+ "window.scrollBy(0, elementTop-(viewPortHeight/2));";
     
((JavascriptExecutor) driver).executeScript(scrollElementIntoMiddle, webElement);
     
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(false);",webElement);
     
Thread.sleep(1000);
     
if (webElement.isDisplayed() && webElement.isEnabled()) {
         
WebDriverWait wait = new WebDriverWait(driver, 10);
         wait
.until(ExpectedConditions.elementToBeClickable(webElement));
         
Thread.sleep(1000);
         action
.moveToElement(webElement).click(webElement).perform();
       
//webElement.click();
       
//((JavascriptExecutor) driver).executeScript("arguments[0].click();",webElement);
     
}
   
} catch (Exception e) {
    currentKeywordErrorMessage
= e.getMessage();
   
return Constants.KEYWORD_FAIL + " --> " + ApplicationTest.currentTestSuite + " - " +ApplicationTest.currentTestCaseName+ " - " + ApplicationTest.currentTestStepID +" ,  Reason:- " + " Unable to click, " + e.getMessage();
   
}
 
return Constants.KEYWORD_PASS;
 
}

I have my wait times, checking if element is clickable, tried using javascript executor to click. I still have issue, not sure what might be wrong. Using up to date version selenium, gecko and firefox browser.

Any suggestions?

Thanks
Nagendra
 
Reply all
Reply to author
Forward
0 new messages