• chinal patel
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hi all, 

i have tried again several hours to find a solution for the following problem. I have a button in the frontend that does not have a unique name nor ID with which i can access it through silenium to click it. Only solution i have is xpath. 

This is the story: 

I try to click the button through this way: 
WebElement myButton = webDriver.findElement(By.xpath("//*[@class='here is the xpath to my button']"));
myButton.click();
it throws an exception saying this: 
</button> is not clickable at point (1851, 325). Other element would receive the click:

i have googled and found 3 possible solutions: 

1. add implicit wait
WebDriverWait wait = new WebDriverWait(webDriver, timeout);
webDriver.manage().timeouts().implicitlyWait(timeout, TimeUnit.SECONDS);
element = wait.until(ExpectedConditions.elementToBeClickable(MYBUTTON));
wait.until(ExpectedConditions.elementToBeClickable(MYBUTTON)); 
MYBUTTON.click();
still the same error from above: </button> is not clickable at point (1851, 325). Other element would receive the click:

2. use action with offset
Actions action = new Actions(webDriver);
action.moveToElement(myButton, 0, -20).contextClick().perform();
action.moveToElement(myButton, 0, -20).click().perform();
action.moveToElement(myButtons, 0, -20).doubleClick().perform();
result: nothing happens. it does not click the element. but context click is shown on the button itself. strange that click does not work. 

3. use javascriptexecutor with offset
((JavascriptExecutor)webDriver).executeScript("window.scrollTo(0,"+clickableAddProduct.getLocation().x+")");
clickableAddProduct.click();
result: still the same error from above: </button> is not clickable at point (1851, 325). Other element would receive the click:

4. execute java script with javascriptexecutor
js.executeScript(	"window.document.getElementByxpath('XPATH TO MYBUTTON').click()");
Result: no such method getElementByxpath exists 

only possible solution i have test is:
- give the button an ID (for example ID="unique ID of MYBUTTON"). during runtime in the inspector of chrome (F12)
- try this below
try {
			// Find the element...
			WebElement element = MYBUTTON;

			// Step 1
			new Actions(webDriver).moveToElement(element).perform();

			// Step 2
			element.click();
		} catch (Exception e) {

			((JavascriptExecutor) webDriver).executeScript("document.getElementById('unique ID of MYBUTTON').click();");

		}

code then it works withe the java script executor line (the one in the exception). i debugged it. worked. 

please can someone help. tried so many ways. frustrating. :(

Thanks
Soheil