-2

How to click on the button element?

Here is the HTML:

<button class="ui-button ui-widget ui-state-default ui-corner-all ui- 
button-icon-only ui-dialog-titlebar-close" type="button" role="button" 
aria-disabled="false" title="close">
<span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span>
<span class="ui-button-text">close</span>
</button>

The error is "Element is not clickable at point (1165.88330078125, 427.76666259765625). Other element would receive the click: Command duration or timeout: 77 milliseconds"

I am on Selenium 2.53.1, if that helps.

I am using Java to write automation scripts.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • please provide your java code with html dom code. Just by reading error its not make any clarification of issue. – Ashish Kamble Oct 15 '18 at 09:47
  • Update the question with your coding trials. – undetected Selenium Oct 15 '18 at 09:48
  • driver.findElement(By.XPath("*//button[@title='close']")); – Ashish Kamble Oct 15 '18 at 09:54
  • @AshishKamble When I try to paste more HTML in the body, it throws an error "Your post appears to contain code that is not properly formatted as code. Please indent all code by 4 spaces using the code toolbar button or the CTRL+K keyboard shortcut. For more editing help, click the [?] toolbar icon." – Sai Krishna Pulivarthi Oct 15 '18 at 10:04
  • firstly when you write your question in formal text not code then dont give up any spaces before stating word in your case "Here" is stating word. ok write your all TEXT then give two spaces press enter. it will bring you new line. when you paste your code select all code you pasted as it is and then make it 'ctrl + k' or simply put four spaces for each code line. There is space at the starting for TEXT. There is four spaces at the starting of code. Hope you will get that soon Sorry but your question has been closed thats why – Ashish Kamble Oct 15 '18 at 10:09
  • Thank you @AshishKamble please check if the HTML is now visible. – Sai Krishna Pulivarthi Oct 15 '18 at 10:15
  • @AshishKamble after trying out your suggestion on using the xpath, i get a new error which i updated on the body of the question. – Sai Krishna Pulivarthi Oct 15 '18 at 10:17
  • can you provide your java code for click() method from your script – Ashish Kamble Oct 15 '18 at 10:47
  • 1
    please go through this question's answers, https://stackoverflow.com/questions/44912203/selenium-web-driver-java-element-is-not-clickable-at-point-36-72-other-el Read answer of @DebanjanB you will get your problem solved. There are six factors that affects such issue. – Ashish Kamble Oct 15 '18 at 10:49
  • @AshishKamble driver.findElement(By.xpath("*//button[@title='close']")).click(); – Sai Krishna Pulivarthi Oct 15 '18 at 10:49
  • Try this, var element = element(By.xpath("*//button[@title='close']")); browser.executeScript("arguments[0].click()",element); OR try this, WebElement ele = driver.findElement(By.xpath("*//button[@title='close']")); JavascriptExecutor executor = (JavascriptExecutor)driver; executor.executeScript("arguments[0].click();", ele); – Ashish Kamble Oct 15 '18 at 10:52
  • Too many errors for the two lines, can you please explain that two lines? – Sai Krishna Pulivarthi Oct 15 '18 at 10:55
  • this is all becoz of viewPort Element not getting clicked as it is not within Viewport – Ashish Kamble Oct 15 '18 at 11:34
  • @AshishKamble //this will get the text from the pop up. wait.until(ExpectedConditions.elementToBeClickable(By.xpath("*//button[@title='close']"))); String output = driver.findElement(By.xpath(".//*[@id='lblForgotSuccess']")).getText(); System.out.println(output); Thread.sleep(10000); //this will click the close button of the pop up. WebElement ele = driver.findElement(By.xpath("*//button[@title='close']")); JavascriptExecutor executor = (JavascriptExecutor)driver; executor.executeScript("arguments[0].click();", ele); This skips print statements – Sai Krishna Pulivarthi Oct 15 '18 at 11:56
  • what you want to print from close button ??? String output works right ? – Ashish Kamble Oct 15 '18 at 12:04
  • @AshishKamble it should work, but it is supposed to print a message which is displayed, and then it should click on close button, after your suggestion, it works on clicking the close button, then, the programs just ignores the print statements, I even tried thread.sleep and explicit wait as well, I will try with implicit and see if that works..I really appreciate you taking time to help me out here, thank you so much. – Sai Krishna Pulivarthi Oct 15 '18 at 12:41
  • you mean 'javascriptexecutor' gets executed so fast even before of System.out.println(output); Use directly System.out.println(""+driver.findElement(By.xpath(".//*[@id='lblForgotSuccess']")).getText()); Lets check if this worked – Ashish Kamble Oct 15 '18 at 12:44
  • Put debug point check do you really get value in string output or not ? Is gets call to SOP or not – Ashish Kamble Oct 15 '18 at 12:49
  • I tried to post all the java code here and followed all the code block instructions to post i wasted one hour here and it does not approve my code, this is just sick, I though this is a great community. but looks like the moderators dont want users to be happy after all. – Sai Krishna Pulivarthi Oct 15 '18 at 13:29
  • They just want to delete stuff by down voting a question if they just find a few words similar to other questions, this is real sick,, not a friendly community. I am outta here. – Sai Krishna Pulivarthi Oct 15 '18 at 13:30
  • @AshishKamble I really thank you so much for working on this, hope you have a wonderful week and good luck! – Sai Krishna Pulivarthi Oct 15 '18 at 13:31

1 Answers1

0

To click on the desired element you need to induce WebDriverWait for the desired element to be clickable and you can use either of the following solutions:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.ui-button.ui-widget.ui-state-default.ui-corner-all.ui-button-icon-only.ui-dialog-titlebar-close[title='close']>span.ui-button-text"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-dialog-titlebar-close' and @title='close']/span[@class='ui-button-text' and contains(.,'close')]"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352