I am getting the following error when I attempt to click a button:
org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 10.06 seconds
I've tried the following and none worked:
1) Waiting for 10 seconds in case the page is being loaded
2) Used JS executor thus:
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", By.cssSelector("#IconButton > input.IconButtonDisplay"));
3) Used wait until element is visible
Number 2 is actually executed but the results of the click don't eventuate i.e. new page does not open.
Number 3 times out stating button is not visible, but button is visible and can be manually clicked.
What I can tell you is that using the Selenium IDE I am able to playback and click the button no problems.
HTML of button (can't put too much here as proprietary information). Apologies for formatting:
<div widgetid="dijit__WidgetsInTemplateMixin_13" id="dijit__WidgetsInTemplateMixin_13" class="gridxCellWidget">
<div class="IconButton" widgetid="IconButton" id="IconButton" data-dojo-type="ab.cd.ef.gh.IconButton" data-dojo-attach-point="rowBtn1Pt">
<input class="IconButtonDisplay" src="/tswApp/ab/cd/ef/gh/images/edit.png" style="width: 20px;" type="image">
</div>
</div>
In Javascript executor you want to pass the instance of WebElement not the By selector. So change
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", By.cssSelector("#IconButton > input.IconButtonDisplay"));
to
WebElement element = driver.findElement(By.cssSelector("#IconButton > input.IconButtonDisplay"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);
Have you tried just using FirefoxDriver?
FirefoxDriver driver = new FirefoxDriver();
Have you tried just using this? Is this not unique enough?
driver.findElement(By.cssSelector("input.IconButtonDisplay")).click();
If not, try this (it's the equivalent to what you were doing with JSE)
driver.findElement(By.cssSelector("#IconButton > input.IconButtonDisplay")).click();
Maybe it's not the INPUT that takes the click? Have you tried clicking either of the parent DIVs?
driver.findElement(By.id("IconButton")).click();
or
driver.findElement(By.id("dijit__WidgetsInTemplateMixin_13")).click();
for me this is what worked:
JavascriptLibrary jsLib = new JavascriptLibrary();
jsLib.callEmbeddedSelenium(driver,"triggerMouseEventAt", editButton,"click", "0,0");
Hope this helps others who are having the same problem.
Related
There is a button on a website I am testing and Selenium can't seem to click it. I have tried many different ways but still nothing. Attached is the HTML for the button as well as the XPath.
Has anyone else experienced this or knows how to get around this?
XPath:
/html/body/div[1]/div/div/form/div[21]/div[3]/button
[HTML]
Could be a synchronization issue. kindly try below solution if your element is not within iframe or else you need to switch control to iframe first before dealing with the web element.
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div[1]/div/div/form/div[21]/div[3]/button"))).click();
Or You can also try javascript solution:
WebElement element= driver.findElement(By.xpath("/html/body/div[1]/div/div/form/div[21]/div[3]/button"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);
Try below code -
Actions action = new Actions(driver);
WebElement My_btn = webdriver.findElement(By.xpath("/html/body/div[1]/div/div/form/div[21]/div[3]/button"));
action.moveToElement(My_btn).click(My_btn).build().perform();
Let me know the outcome.
I have a project that I am working on with java and selenium.
the test work OK in UI mode.
However in headless mode I get this error
org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <label _ngcontent-yrc-c26="" formcontrolname="reportingDealPermission" nz-checkbox="" class="ant-checkbox-wrapper ng-untouched ng-pristine ng-valid" ng-reflect-name="reportingDealPermission">...</label> is not clickable at point (161, 562). Other element would receive the click: <div _ngcontent-yrc-c26="" class="footer">...</div>
how can I resolve this issue (working in UI mode). this is my code
WebDriver driver = getWebDriver();
WebElement element;
Thread.sleep(60000);
element = driver.findElement(By.xpath("//label[#formcontrolname='reportingDealPermission']"));
element.click();
why in selenium there is no operation to move to the element and break all layers.
this is the UI.
this is working in UI mode not working in headless mode, made sleep for 6 minutes and not resolved so this is not time issue
This error message...
org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <label _ngcontent-yrc-c26="" formcontrolname="reportingDealPermission" nz-checkbox="" class="ant-checkbox-wrapper ng-untouched ng-pristine ng-valid" ng-reflect-name="reportingDealPermission">...</label> is not clickable at point (161, 562). Other element would receive the click: <div _ngcontent-yrc-c26="" class="footer">...</div>
...implies that the click on the desired element was intercepted by some other element.
Clicking an element
Ideally, while invoking click() on any element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:
cssSelector:
new WebDriverWait(getWebDriver(), 10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("label[formcontrolname=reportingDealPermission][ng-reflect-name=reportingDealPermission]"))).click();
xpath:
new WebDriverWait(getWebDriver(), 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//label[#formcontrolname='reportingDealPermission' and #ng-reflect-name='reportingDealPermission']"))).click();
Update
After changing to headless if it still doesn't works and still get exception there still a couple of other measures to consider as follows:
Chrome browser in Headless mode doesn't opens in maximized mode. So you have to use either of the following commands/arguments to maximize the headless browser Viewport:
Adding the argument start-maximized
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("start-maximized");
WebDriver driver = new ChromeDriver(options);
Adding the argument --window-size
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--window-size=1400,600");
WebDriver driver = new ChromeDriver(options);
Using setSize()
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
WebDriver driver = new ChromeDriver(options);
driver.manage().window().setSize(new Dimension(1440, 900));
You can find a detailed discussion in Not able to maximize Chrome Window in headless mode
Additionally, you can also wait for the intercept element to be invisible using the ExpectedConditions invisibilityOfElementLocated before attempting the click() as follows:
cssSelector:
new WebDriverWait(getWebDriver(), 10).until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector("div.footer")));
new WebDriverWait(getWebDriver(), 10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("label[formcontrolname=reportingDealPermission][ng-reflect-name=reportingDealPermission]"))).click();
xpath:
new WebDriverWait(getWebDriver(), 10).until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//div[#class='footer']")));
new WebDriverWait(getWebDriver(), 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//label[#formcontrolname='reportingDealPermission' and #ng-reflect-name='reportingDealPermission']"))).click();
References
You can find a couple of related relevant discussions in:
Selenium Web Driver & Java. Element is not clickable at point (x, y). Other element would receive the click
Element MyElement is not clickable at point (x, y)… Other element would receive the click
Try adding an explicit wait
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//label[#formcontrolname='reportingDealPermission']"))).click();
and if this doesn't work then try using the JS Executor
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//label[#formcontrolname='reportingDealPermission']")));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", element);
None of the above answers worked for me. Try using action class as follows:
WebElement element = driver.findElement(By.xpath("//div[#class='footer']"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();
For this issue:
org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <label _ngcontent-yrc-c26="" formcontrolname="reportingDealPermission" nz-checkbox="" class="ant-checkbox-wrapper ng-untouched ng-pristine ng-valid" ng-reflect-name="reportingDealPermission">...</label> is not clickable at point (161, 562).
Another element receives the click:
Answer is to explicitly wait with javascript executor. This combination is working for me:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//label[#formcontrolname='reportingDealPermission']")));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", element);
WebDriverWait wait = new WebDriverWait(driver, 10); ---> has deprecated and it gives an error. Please use below instead:
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//label[#formcontrolname='reportingDealPermission']"))).click();
Ensure to import relevant items for the WebDriverWait and ExpectedConditions.
In my case "JavaScript" works:
WebElement ele = driver.findElement(By.xpath("(//input[#name='btnK'])[2]"));
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].click()", ele);
It was taken from:
http://makeseleniumeasy.com/2020/05/25/elementclickinterceptedexception-element-click-intercepted-not-clickable-at-point-other-element-would-receive-the-click/
Answer is worked for me.
Please check the below sreenshot for the my problem reference.
Below alert is comes in between the the my button and frame.
enter image description here
In my case, nothing worked. Only the THREAD.SLEEP() method worked!
How to write the selenium code for Scroll down the mouse below. I try to use the below code it was not scrolling action.
JavascriptExecutor Scrool = (JavascriptExecutor) driver;
Scrool.executeScript("window.scrollBy(0,250)", "");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
use this method. Call this method with actual webelement where you would like to scroll
public void scrollToElement(WebElement element) {
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
}
#tester
so, first of all, you need to be careful with automation. Before to start the automation check website and be sure that there are no iframes. in your case on your website, you have IFRAME that's why you are getting no such element exception which means your code not reaching this web element.
so to handle this problem you can run it in 2 ways.
the first way to scroll to webelement which you need
driver.get("https://www.abservetechdemo.com/products/rebueats/");
driver.switchTo().frame(0);
WebElement scrollToelement = driver.findElement(By.xpath(" //h2[contains(text(),'Your restaurant, delivered')]"));
((JavascriptExecutor) driver.executeScript("arguments[0].scrollIntoView(true);", scrollToelement);
and the second way just uses your own code but add this driver.switchTo.iframe(0). in your case, you have only 1 iframe so 0 means index of the iframe.
driver.get("https://www.abservetechdemo.com/products/rebueats/");
driver.switchTo().frame(0);
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("scrollBy(0,2500)");
I am sure this will solve your issue I test it couple times
Trying to use explicit wait but it is not working. If Thread.sleep is added it works perfectly fine. Selenium WebDriver 3 and Firefox 55. Below is the code.
Code
WebDriverWait wait=new WebDriverWait(driver, 30);
WebElement w1 = driver.findElement(By.xpath("//*[#id='formdesigner']"));
wait.until(ExpectedConditions.elementToBeClickable(w1));
driver.findElement((By.xpath("//*[#id='formdesigner']"))).click();
Have also tried Actions class move to element and then click but same problem. Checked for element displayed, it is displayed but still no click happening and no error displayed. Please help me to get the solution for this. Can't keep on using Thread.sleep as it is not correct to do so.
HTML code:
HTML code
<div class="col-sm-6 full-height">
<div id="formdesigner" class="row full-height">
<div class="col-sm-12 tile-name">FORM DESIGNER</div>
<div class="col-sm-12 tile-image">
<div class="link-img"/>
</div>
</div>
</div>
Instead of :
WebDriverWait wait=new WebDriverWait(driver, 30);
WebElement w1 = driver.findElement(By.xpath("//*[#id='formdesigner']"));
wait.until(ExpectedConditions.elementToBeClickable(w1));
driver.findElement((By.xpath("//*[#id='formdesigner']"))).click();
Try this code block :
WebDriverWait wait2 = new WebDriverWait(driver, 10);
WebElement w2 = wait2.until(ExpectedConditions.elementToBeClickable((By.xpath("//div[#id='formdesigner']/div[#class='col-sm-12 tile-name']"))));
w2.click();
When you are waiting for element, at first you should never declare WebElement and then wait for it. When you declare a WebElement it should be readily available for WebDriver on browser.
Initially, you need to wait for element(declare or initialise element inside wait) in wait statement like below
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("your xpath or id")));
or
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("your xpath")));
and then declare your element here for further operations.
You can use ID with JavascriptExecutor as alternative if wait is not working
WebElement element = driver.findElement(By.id("formdesigner"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
Try using implicit wait as shown below.
WebElement w1 = driver.findElement(By.xpath("//*[#id='formdesigner']"));
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement((By.xpath("//*[#id='formdesigner']"))).click();
This worked for me.
I am trying to automate functional testing of a web application using Selenium webdriver and Java.
In the AUT, there is a 'Submit' button defined by the following html code
<button id="submitbtn" class="btn btn-primary" type="submit">Submit</button>
I use the following command to click the button.
driver.findElement(By.id("submitbtn")).click();
When I run the code, the webdriver can find the button but the click action is not performed (I can understand that webdriver can find the button because no exception is thrown and the I can see a selection on the button when the code is run). I tried different waits
new WebDriverWait(driver,60).until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("submitbtn"));
but not getting any positive result. If I use,
Thread.sleep(3000);
it works fine (but I want to avoid this code). I tried all other types of waits and action class,
Actions action=new Actions(driver);
action.moveToElement(driver.findElement(By.id("submitbtn"));
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("submitbtn")));
action.click().perform();
but no luck. Is there any way to achieve this?
How about JavascriptExecutor?
WebElement element = driver.findElement(By.id("submitbtn"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
A submit() is an option driver.findElement(By.id("submitbtn")).submit();. More information here