could able to get the text of an web element, but not able to click it

25 Views Asked by At

Page contains a input box with a side button with '+' on it. I could clear the input box, send some text in to it, then when I could get the web element reference of the '+' button, but for the love of God, I could not able to click on it by using any means under 'Selenium v4.0', like plain web element click(), or Actions class or even JavaScriptExecutor. Also noteworthy is I am using fluentwait up 100sec. Please see below titbits of code I used and pic of the screen.

 1. waitingDriver = new WebDriverWait(driver,Duration.ofSeconds(100)); 
    WebElement someBtn=waitingDriver.until((ExpectedConditions.elementToBeClickable(by)));
    someBtn.click();// would not able to click
    System.out.println("btnClickBy, Text="+someBtn.getText());// returns text as '+'

 2. JavascriptExecutor executor = (JavascriptExecutor) driver;
    executor.executeScript("arguments[0].click();", someBtn);// would not able to click

 3. Actions actions = new Actions(driver);
    actions.moveToElement(someBtn).click().perform();// would not able to click

The source code looks like this... source codescreen pic

1

There are 1 best solutions below

0
On

Later to the posting, I have observed that in most of the cases, the run time is not able to execute just one button click next to an input box. I could retrieve the text on the button, but could not be able to click on it.

So, after many ways of writing Selenium locators, I finally went to JavaScript executor interface, which did work !! So once crossed that road block, the rest is keeping more amount of wait times in the form of fluent waits with conditional ExpectedConditions clause. All the elements are accessible with little or no problem.

Lesson learnt: When you are testing website made out of the javaScript based libraries, try the conditional fluent waits with ExpectedConditions and finally don't forget to use JavaScript executor interface for your click actions.