I am not able to click the element. When I am executing my test in a computer it runs perfectly, but when I am executing my test in a laptop it is failing. Getting error Element not clickable. I have tried to use different wait times as well. Have no idea where is issue. This is what I am using :
WebDriverWait wait=new WebDriverWait(driver,30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//button[#ng-click='startExam()']"))).click;
Action action=new Actions(driver);
actions.moveToElement(ele).perform();
action.movetoElemet(ele).click().perform.
This what I have in inspect console:
<button class="btn btn-primary ng-scope" ng-if="!proctoredSession" ng-click="startExam()" ng-dissabled="!isExamContentLoaded">Start Exam</button>==$0
Try this:
((JavascriptExecutor) driver).executeScript("arguments[0].click();", driver.findElement(By.cssSelector("button[ng-click='startExam()']"));
or
WebElement button = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("button[ng-click='startExam()']")));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true)",button);
button.click();
As per the HTML within your question the element is an Angular element so you need to induce WebDriverWait for the element to be clickable and you can use either of the following solution:
CSS_SELECTOR:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.btn.btn-primary.ng-scope[ng-click^='startExam']"))).click();
XPATH:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[#class='btn btn-primary ng-scope'][contains(.,'Start Exam')]"))).click();
You may update your existing code as following:
WebDriverWait wait=new WebDriverWait(driver,30);
Action action=new Actions(driver);
WebElement temp = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//button[#ng-click='startExam()']")));
action.moveToElement(temp).click().perform();
Related
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!
HTML:
Apply Now
I have already tried the following:
driver.findElement(By.xpath("//a[text()='Apply Now']")).click();
driver.findElement(By.xpath("(.//[#href='Apply Now'])")).click();
driver.findElement(By.xpath("//a[#href='Apply Now']")).click();
driver.findElement(By.linkText("Apply Now")).click();
driver.findElement(By.className("Apply Now")).click();
driver.findElement(By.xpath("//div[contains(#class,'btn btn-success btn-lg')]")).click();
driver.findElement(By.xpath("//div[contains(#class,'btn btn-success btn-lg')]")).click();v
Try to click with webdriver wait till element is properly loaded in Dom and ready to receive click.
WebDriverWait wait = new WebDriverWait(driver, 40);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[.='Apply Now']"))).click();
Option 1
Try By.CssSelector
Option 2
Not sure if you are checking if element is exists before clicking on it.if not then use wait.until.
If possible paste error you are getting here.
Hope this helps.
The desired element is a dynamic element so to locate and click() on the element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:
linkText:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.linkText("Apply Now"))).click();
cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.btn.btn-success.btn-lg[href*='associateregistration']"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#class='btn btn-success btn-lg' and contains(#href, 'associateregistration')][text()='Apply Now']"))).click();
Try this please, maybe it will help
driver.findElement(By.id("select2-section-tn-container")).click();
I want to click "Action" button and select the option "Update Reference data".
Here is my code
Thread.sleep(30000);// To load the page
driver.findElement(By.xpath("//*[#id=\"spend_mgmt_actions_menu\"]")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//*[id=\"upgradeRefData_button\"]")).click();
I also tried this, but got the same exception
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#id=\"spend_mgmt_actions_button\"]")));
driver.findElement(By.className("button show-right-icon f-dropdown-facade actions-list-button plan-action-button")).click();
Thread.sleep(20000);
But when I run the code it gives:
No Such Element Exception unable to locate.....
Below is the HTML code copied from browser by selecting the element.
<button id="spend_mgmt_actions_button"
class="button show-right-icon f-dropdown-facade actions-list-button plan-action-button"
aria-hidden="false" aria-haspopup="true" data-dropdown="spend_mgmt_actions_menu" tabindex="0">
<span>Actions</span><span class="icon icon-right fa fa-caret-down"></span></button>
<button id="upgradeRefData_button" class="list-item dd-item" aria-disabled="false"
data-dropdown-item="" role="menuitem" tabindex="0" title=""><span>Update Reference Data</span>
</button>
You were close. To click() on the element with text as Actions and then to click() the element with text as Update Reference Data you have to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:
cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.button.show-right-icon.f-dropdown-facade.actions-list-button.plan-action-button#spend_mgmt_actions_button>span"))).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.list-item dd-item#upgradeRefData_button>span"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[#class='button show-right-icon f-dropdown-facade actions-list-button plan-action-button' and #id='spend_mgmt_actions_button']/span[text()='Actions']"))).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[#class='list-item.dd-item' and #id='upgradeRefData_button']/span[text()='Update Reference Data']"))).click();
I'm automating some website in which I need to log out. I'm facing a hard time in this code:
WebDriverWait wait = new WebDriverWait(d, 10);
WebElement Category_Body = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("user logout")));
Category_Body.click();
d.findElement(By.id("logout_user")).click();
Thread.sleep(1000);
HTML:
<a class="user logout" title="Sign out" data-target="#confirm_popup" data-toggle="modal"></a>
Error:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"user logout"}
Try the following code for that:
WebDriverWait wait = new WebDriverWait(d, 10);
WebElement Category_Body = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".user.logout")));
Category_Body.click();
PS: You can do this with ExpectedCondition.elementToBeClickable, also.
Hope it helps you!
I think the issue is with the identifier
You have used
WebElement Category_Body = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("user logout")));
But according to your HTML
<a class="user logout" title="Sign out" data-target="#confirm_popup" data-toggle="modal"></a>
The link have no id called "User Logout"
With out using id try to use class By.findElementByClassName("user logout")
As a Second solution, try to use xpath ( which will work most of the time )
If both the solutions are not usable you can use the JavascriptExecutor ( The elements which are hard to capture can be easily handled with JavascriptExecutor )
NOTE: The main issue is with you using "user logout" when there is no such ID
Cheers
As per your to locate the desired element to logout within the Model Box you need to induce WebDriverWait for the element to be clickable and you can use either of the the following options:
cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.user.logout[title='Sign out'][data-toggle='modal']"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#class='user logout' and #title='Sign out'][#data-toggle='modal']"))).click();
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.