Vishnu More
Vishnu More

Reputation: 45

Getting "Element is not currently visible and so may not be interacted with" error in Selenium webdriver for below HTML

I am getting "Element is not currently visible and so may not be interacted with" error in selenium web-driver.

Here I am trying to select the Page text and clicking on the button for additional operations but the given element , below line i have wrote in selenium web-driver .

driver.findElement(By.cssSelector("div.annotator-adder")).click();

and the below is the HTML for the button :

div class="annotator-adder" style="display: block; top: 359px; left: 585px;">Annotate

and this HTML for the text selection for adding annotations using the button:

"p section-number="12-1-101.11.12" class="abbrevation ICCSECONDPARA">The Division of the State Architect has been delegated the responsibility and authority by the Department of General Services to review and approve the design and observe the construction of public school buildings and state-owned or state-leased essential services buildings. "

Upvotes: 1

Views: 2620

Answers (3)

murali selenium
murali selenium

Reputation: 3927

As wait is not working, please try with Thread.sleep(6000);

Also you can try with javascript executor to click on element

WebElement element = driver.findElement(By.cssSelector("div.annotator-adder"));
 JavascriptExecutor executor = (JavascriptExecutor)driver;
 executor.executeScript("arguments[0].click();", element);

Thanks

Upvotes: 1

Shoaib Mal
Shoaib Mal

Reputation: 89

It seems like your element is present on the page, but not visible in the browser view port. You can scroll that element into view first and then do the operation. Check here how to scroll element into view : Scroll Element into View with Selenium

Upvotes: 1

Guy
Guy

Reputation: 50809

Try using explicit wait and Expected Conditions

WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.annotator-adder"))).click();

This will wait up to 20 seconds for the element to be visible before the click().

Upvotes: 1

Related Questions