MyElement element does not click at (x, y) ... Another element will receive a click

I am trying to do some tests using Katalon Studio Selanium. In one of my tests, I have to write inside a text box. The problem is that I get the following error:

...Element MyElement is not clickable at point (x, y)... Other element would receive the click... 

In fact, my element is placed inside some other div that can hide it, but how can I make the click event by clicking on my text area?

+13
source share
4 answers

Element... is not clickable at point (x, y). Other element would receive the click" Element... is not clickable at point (x, y). Other element would receive the click" Element... is not clickable at point (x, y). Other element would receive the click" can be caused by various factors. You can eliminate them in one of the following ways:

  1. Element not clicked due to JavaScript or AJAX calls

Try using the Actions class:

 WebElement element = driver.findElement(By.id("id1")); Actions actions = new Actions(driver); actions.moveToElement(element).click().build().perform(); 
  1. The item does not get clicked, as it is not included in the Viewport

Try using the JavascriptExecutor to cast an element to the Viewport:

 JavascriptExecutor jse1 = (JavascriptExecutor)driver; jse1.executeScript("scroll(250, 0)"); // if the element is on top. jse1.executeScript("scroll(0, 250)"); // if the element is at bottom. 

Or

 WebElement myelement = driver.findElement(By.id("id1")); JavascriptExecutor jse2 = (JavascriptExecutor)driver; jse2.executeScript("arguments[0].scrollIntoView()", myelement); 
  1. The page is refreshed before the item becomes clickable.

In this case, induce a little wait .

  1. An element is present in the DOM, but is not clickable.

In this case, add a few ExplicitWait so that the element is active.

 WebDriverWait wait2 = new WebDriverWait(driver, 10); wait2.until(ExpectedConditions.elementToBeClickable(By.id("id1"))); 
  1. The item is present but has a temporary overlay.

In this case, call ExplicitWait with ExpectedConditions set to invisibilityOfElementLocated so that Overlay is invisible.

 WebDriverWait wait3 = new WebDriverWait(driver, 10); wait3.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("ele_to_inv"))); 
  1. The element is present but has a constant overlay.

Use the JavascriptExecutor to send a click directly to an element.

 WebElement ele = driver.findElement(By.xpath("element_xpath")); JavascriptExecutor executor = (JavascriptExecutor)driver; executor.executeScript("arguments[0].click();", ele); 
+18
source

I assume that you have already checked that there are no other overlapping components (transparent advertising frames or some other DOM => component that are quite common in input / text field elements), as well as stepwise (slow) In the manual step, your code works fine, then ajax calls can cause this behavior.

To avoid thread.sleep, try sticking to EventFiringWebDriver and register a handle for it. (Depending on your technical application stack, you can use it for Angular, JQuery or wicket in a handler, which will require different implementations) (By the way: this approach also saved me the “StaleElementException” many times)

see org.openqa.selenium.support.events.EventFiringWebDriver org.openqa.selenium.support.events.WebDriverEventListener

 driveme = new ChromeDriver(); driver = new EventFiringWebDriver(driveme); ActivityCapture handle=new ActivityCapture(); driver.register(handle); 

=> ActivityCapture implements a WebDriverEventListener, for example, javascriptExecutor for working with Ajax calls in the wicket / dojo tech stack

  @Override public void beforeClickOn(WebElement arg0, WebDriver event1) { try { System.out.println("After click "+arg0.toString()); //System.out.println("Start afterClickOn - timestamp: System.currentTimeMillis(): " + System.currentTimeMillis()); JavascriptExecutor executor = (JavascriptExecutor) event1; StringBuffer javaScript = new StringBuffer(); javaScript.append("for (var c in Wicket.channelManager.channels) {"); javaScript.append(" if (Wicket.channelManager.channels[c].busy) {"); javaScript.append(" return true;"); javaScript.append(" }"); ; ; ; javaScript.append("}"); javaScript.append("return false;"); //Boolean result = (Boolean) executor.executeScript(javaScript.toString()); WebDriverWait wait = new WebDriverWait(event1, 20); wait.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driver) { return !(Boolean) executor.executeScript(javaScript.toString()); } }); //System.out.println("End afterClickOn - timestamp: System.currentTimeMillis(): " + System.currentTimeMillis()); } catch (Exception ex) { //ex.printStackTrace(); } } 
+3
source

Try Thread.Sleep ()

Implicit - Thread.Sleep ()

So this is actually not a feature of Selenium WebDriver, although it is common in most programming languages. But none of this matters.

Thread.Sleep () does exactly what you think it is sleeping thread. Therefore, when your program starts, in most cases this program will be an automatic check, they are performed in a thread. Therefore, when we call Thread.Sleep, we instruct our program to do nothing for a certain period of time, just sleep. No matter what our test application is aiming for, we don’t care, our checks have time to take a nap!

Unfortunately, quite often you can see several instances of Thread.Sleep () in the Selenium WebDriver GUI validation frameworks. What usually happens is that the script will crash or crash from time to time, and someone runs it locally and realizes that there is a race that WedDriver sometimes plays. It may happen that the application sometimes takes longer to load, possibly when it has more data, so to fix this, they ask WebDriver to take a nap to make sure the application loads before continuing with the scan.

Thread.sleep (5000);

The value provided is indicated in milliseconds, so this code will pause verification for 5 seconds.

0
source

I made a post about this in Python and was marked as a duplicate and sent me to this post. I tried everything I found here and some other posts.

The problem was that I was getting an exception in the Select element and could not use the script to click, although I tried it, it did not work.

Since I wanted to select an element using visible text (not by value or option number), I used the following code, which is to find the element using Xpath [contains (text (), 'text')] and then change the HTML Maybe this is useful for another.

 self.driver.execute_script( "arguments[0].selected=true", self.driver.find_element_by_xpath( '//*[contains(text(), "%s" )]' % 'your_visible_text' ), ) 
0
source

Source: https://habr.com/ru/post/1269161/


All Articles