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.
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!
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();
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();
I am trying to code in java using selenium webdriver to click on Dropdown list in walmart page. But I am unable to access the li elements.
<button class="js-flyout-toggle dropdown" aria-haspopup="true" type="button" data-cat-id="0" aria-expanded="false"> All </button>
<div class="js-flyout-modal flyout-modal">
<ul class="block-list">
<li><button class="no-margin font-semibold" type="button" data-cat-id="0" tabindex="-1"> All Departments </button></li>
<li><button class="no-margin font-semibold" type="button" data-cat-id="91083" tabindex="-1"> Auto & Tires </button></li>
<li><button class="no-margin font-semibold" type="button" data-cat-id="5427" tabindex="-1"> Baby </button></li>
I wanted to access Baby using selenium webdriver in Java.
Below is my code:
driver.get("http://www.walmart.com");
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement dropdown = driver.findElement(By.xpath("html/body/div[2]/header/div[3]/div/div/div/div/div[3]/form/div/div[1]/div/button"));
dropdown.click();
List<WebElement> liElements = driver.findElements(By.xpath("//*[#class='block-list']/li"));
for ( WebElement we: liElements) {
System.out.println(we.getText());
}
But this gives an error as below:-
"Exception in thread "main"
org.openqa.selenium.ElementNotVisibleException: Element is not
currently visible and so may not be interacted with Command duration
or timeout: 132 milliseconds".
Please help
You defined WebDriverWait but you don't use it
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement dropdown = wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("dropdown")));
Implicit wait will wait for element to exist in the DOM. If you want to use explicit wait you need to use Expected Conditions as well. Only defining WebDriverWait doesn't actually do anything.
Your code looks fine. Please try below xpath :-
//div[#class='js-flyout-modal flyout-modal']//ul[#class='block-list']/li
Now first try to put thread.sleep if it works then it is problem of wait only
Thread.sleep(30000);
But then don't use Thread for your script as it's not recommended .. It's just to ensure that script is failing because of time
Hope it will help you :)
May be other element in walmart page match your xpath //*[#class='block-list']/li and that element is not visible.
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.