I have been trying to get my Automation Tests up and Running but keep running into some Xpath Errors. I am having 5 errors all with missing/not being able to locate the Xpath that I have wrote. I need to have my test click on a "Refresh" Button located in a data table that is located on the Web page. Button instead of clicking on the button I get the error below. The ID of the button is "SF-Refresh" .
#When("I click refresh button")
#Given("I click refresh button")
#Then("I click refresh button")
public void clickRefreshButton() {
By linkSelect = new By.ByXPath("//*[#id=\"SF-Refresh\"]");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
LightningButton.click(linkSelect);
}
Error:
Unable to locate the requested element: By.xpath: //*[#id="SF-Refresh"]
There is few possible error as below:
1) The Xpath is might wrong or same Xpath return multiple elements, the xpath must return one element only if you are using findElement
2) The element is might not load properly yet or not ready for action use below:
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#id="SF-Refresh"]")));
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[#id="SF-Refresh"]")));
LightningButton.click(linkSelect);
Related
I am looking for the condition in cypress to verify and click locator is present or not.
If element is present go to condition and click on the element else leave and continue with the execution. Below code i have tried,
cy.get(".paginationPanel.ng-star-inserted").then(($test)=> {
if($test.text().includes('Show:')){
//do something
}else{
}
})
Unfortunately, I am unable to success. Can anyone please help me.
That code works, what is wrong?
What do you want to click? The "Show" dropdown would be
cy.get(".paginationPanel").then(($panel) => {
if($panel.text().includes('Show:')) {
cy.contains('label', 'Show').prev().click() // click the Show dropdown
} else {
}
})
I am unable to click on sign in button in mobile using Appium.
I have used xpath & androidUiAutomator but unable to succeed.
Following are the details:
For Xpath i used:
//android.widget.TextView[#text='Sign In']
For AndroidUiAutimator i used:
return driver.findElementByAndroidUIAutomator("text(\"Sign In\")");
public void MainLogin() throws InterruptedException {
System.out.println("Enter in Epcl_MainLogin");
TouchAction touch=new TouchAction(driver);
WebDriverWait wt=new WebDriverWait(driver,20);
LoginPom objLogin = new LoginPom(driver);
wt.until(ExpectedConditions.visibilityOf(objLogin.LoginName()));
objLogin.LoginName().sendKeys("Testa");
TimeUnit.SECONDS.sleep(2);
driver.hideKeyboard();
objLogin.LoginPassword().sendKeys("Testb");
TimeUnit.SECONDS.sleep(4);
driver.hideKeyboard();
objLogin.BtnLogin().click();
System.out.println("Button Clicked Successfully");
TimeUnit.SECONDS.sleep(8);
System.out.println("Login Successfully");
}
you can add content-description to your sign in button (in your android code). Then you will be able to click the button by using
driver.findElementByAccessibilityId("your content description").click()
You can also add id to your button and click it using:
driver.findElementById("you button id").click();
Using xpath in appium is not recommended
In regards to the Webdriver error
Element is not clickable at point (X, Y). Another element would recieve the click instead.
For ChromeDriver, this is addressed at Debugging "Element is not clickable at point" error, however the issue can occur in Firefox as well.
What are the best ways to resolve this when it occurs in FirefoxDriver?
This happens in the below cases-
When the element is loaded into the DOM, but the position is not
fixed on the UI. There can be some other div or images that are not
loaded completely.
The page is getting refreshed before it is clicking the element.
Workaround
Use Thread.sleep before actions on each web element in UI, but it is
not a good idea.
Use WebDriverWait ExpectedConditions.
I was facing the same issue, the page load time was more and a loading icon was overlapping on entire web page.
To fix it, I have implemented WebDriverWait ExpectedConditions, which waits for the loading icon to disappear before performing click action on an element
Call this function before performing an action (I am using data driven framework)
public void waitForLoader () throws Exception {
try {
String ObjectArray[]=ObjectReader.getObjectArray("LoadingIcon");
if(checkElementDisplayed(ObjectArray[3],ObjectArray[2]))
{
WebDriverWait wait = new WebDriverWait(remotewebdriver,10);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath(ObjectArray[3])));
}
} catch (NoSuchElementException e) {
System.out.println("The page is loaded successfully");
}
}
If your problem is that the element is scrolled off the screen (and as a result under something like a header bar), you can try scrolling it back into view like this:
private void scrollToElementAndClick(WebElement element) {
int yScrollPosition = element.getLocation().getY();
js.executeScript("window.scroll(0, " + yScrollPosition + ");");
element.click(); }
if you need you could also add in a static offset (if for example you have a page header that is 200px high and always displayed):
public static final int HEADER_OFFSET = 200;
private void scrollToElementAndClick(WebElement element) {
int yScrollPosition = element.getLocation().getY() - HEADER-OFFSET;
js.executeScript("window.scroll(0, " + yScrollPosition + ");");
element.click();
}
You can direct click using JavascriptExecutor (Not recommanded)
WebElement element= driver.findElement(By."Your Locator"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);
Hope it will help you :)
My same problem is solved by Javascript, Please try following code instead of selenium click
WebElement rateElement = driver.findElement(By.xpath(xpathContenRatingTab));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", rateElement);
Careful matching of the Selenium jar version with the Firefox version can fix the issue. Selenium should automatically scroll an element into view if it isn't on the page. Forcing an element into view with JavaScript is unnecessary.
We never see this issue in Firefox 31.5.0 with selenium-server-standalone-2.44.0.jar, however when upgrading to Firefox 38.7.0 with selenium-server-standalone-2.52.0.jar, it became an issue.
See https://github.com/seleniumhq/selenium/issues/1543
I had the same problem and I solved it using certain capability. While you are using FirefoxDriver, you can set "overlappingCheckDisabled" to true to solve your problem.
capabilities.setCapability("overlappingCheckDisabled", true);
ActionBuilder can resolve the error. Sometimes there is another element in front of the object that needs to be clicked, so an ActionBuilder click to the location of the element may work in cases where a traditional click fails
Actions actions = new Actions(driver);
actions.moveToElement(clickElement).click().perform();
or try the middle of the element
Actions actions = new Actions(driver);
Integer iBottom = clickElement.getSize().height;
Integer iRight = clickElement.getSize().width;
actions.moveToElement(clickElement, iRight/2, iBottom/2).click().perform();
This Error coud ocur when for example u make to many accesses to some service , for example if u are making as I a bot .... For example instagram will block u for some period if u ar taged as blocked and then that error coud ocour not allowing u to click some elements in the page.
Try make another acount and switch to a vpn becouse probably your ip is already marked as blocked
Try to maximize the browser when you are working with resolutions greater than 1024x768. It works for me in js.
driver.manage().window().maximize();
I have a problem with Dojo in Internet explorer 7/8 (this works fine in Firefox).
Basically I have a tab container with a number of tabs in it (these are dojox.layout.ContentPane's). On one of these tabs I want to have a "comments box" which would popup a dialog and ask the user to put something in. The comment is then saved by an call to the back end and I want the tab to reload to show the new comment.
The logic of my save button works something like this:
<button data-dojo-type="dijit.form.Button" type="button" data-dojo-props="iconClass:'dijitIcon dijitIconSave', showLabel: true" title="Add your comment">Add Comment
<script type="dojo/on" data-dojo-event="click" data-dojo-args="evt">
require(["dojo/dom"], function(dom)
{
var tText = dijit.byId('comment_70').get('value');
if (tText == '')
{
alert('You have not entered any comment');
return;
}
var tJSONRPC = new JSONRpcClient('JSON-RPC');
try
{
tJSONRPC.be.addComment('70', tText);
var tTab = dijit.byId('Detail_70');
tTab.refresh();
}
catch (Ex)
{
alert(Ex);
}
});
</script></button>
Does not appear to be terrible taxing (the 70 at the end is the ID so that the user can have more than one of these open at the same time, hence the tabs).
As mentioned this works fine in Firefox but not in IE 8/7, it throws an error in some of the generated code within dojo (_32.focus(); to be precise), the error message I get in the debug console is "Unexpected call to method or property access"
Try this, with your line tTab.refresh();:
setTimeout(function() { tTab.refresh(); }, 0); // whenIdle
Its nearly impossible to tell where the thrown exception comes from - you should use the developement dojo-1.M.m-src/dojo/dojo.js code so optimized function- and variable-names are expanded (along with useful commenting once you step-through-debug).
Reason for the above is to eliminate, that exception occurs while handling button onclick-focus event (refresh will tear down DOM in the tab - along with your button)
I write automated scripts for testing web applications that are very heavy on ajax. For example, a modal dialog is displayed with the text "Saving..." when saving settings, while a lightbox greys out the rest of the page.
My test scripts are trying to click the next link in the test before the message disappears. It almost always works when driving Firefox, but when driving Chrome the following error is displayed:
Exception in thread "main" org.openqa.selenium.WebDriverException: Element is not clickable at point (99.5, 118.5). Other element would receive the click: <div class="dijitDialogUnderlay _underlay" dojoattachpoint="node" id="lfn10Dijit_freedom_widget_common_environment_Dialog_8_underlay" style="width: 1034px; height: 1025px; "></div> (WARNING: The server did not provide any stacktrace information)
This happens because the lightbox is obscuring the element I want to click on. I want to wait for the lightbox to disappear before attempting to click the link.
Checking for the lightbox to no longer exist is not a valid workaround because there are, at times, multiple levels of modal dialogs and lightboxes, and no easy way to distinguish between them.
Is there a way in Selenium to detect if the element is clickable (no other elements obscuring it)? A try/catch would be a workaround, but I'd prefer to do a proper check if that is possible.
Use the WebDriverWait conditions.
WebDriverWait wait = new WebDriverWait(yourWebDriver, 5);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//xpath_to_element")));
Webdriver will wait for 5 seconds for your element to be able to be clicked.
You can use the ExpectedConditions.invisibilityOfElementLocated(By by) method which waits until the element is either invisible or not present on the DOM.
WebDriverWait wait = new WebDriverWait(yourWebDriver, 10);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("yourSavingModalDialogDiv")));
So, depending on how much time your modal dialog takes to go invisible or go off the DOM, webdriver will wait. The wait is for a maximum of 10 seconds.
You could create a clickUntil function/method that does a WebDriver wait until the element is clickable with a timeout. It would attempt to click on the element, and throw away "Element is not clickable" error messages each time until it becomes clicked or times out.
Not sure how to write that in dojo, but that's an idea.
I also have same problems, but I tested many input in site. One are clickable which I tested and other - not clickable one just skipped. I made it by try() catch()
Simply Code :
for(){ // for all my input
try {
driver.findElement(By.xpath("...."
+ "//input)["+(i+1)+"]")).click();
... tests...
} catch(Exception e) {
if(e.getMessage().contains("is not clickable at point")) {
System.out.println(driver.findElement(By.xpath(locator)).
getAttribute("name")+" are not clicable");
} else {
System.err.println(e.getMessage());
}
}
And more elegant:
#SuppressWarnings("finally")
public boolean tryClick(WebDriver driver,String locator, locatorMethods m) {
boolean result = false;
switch (m) {
case xpath:
try {
driver.findElement(By.xpath(locator)).click();
result= true;
} catch (Exception e) {
if(e.getMessage().contains("is not clickable at point")) {
System.out.println(driver.findElement(By.xpath(locator)).getAttribute("name")+" are not clicable");
} else {
System.err.println(e.getMessage());
}
} finally {
break;
}
case id:
try {
driver.findElement(By.id(locator)).click();
return true;
} catch (Exception e) {
if(e.getMessage().contains("is not clickable at point")) {
System.out.println(driver.findElement(By.id(locator)).getAttribute("name")+" are not clicable");
} else {
System.err.println(e.getMessage());
}
} finally {
break;
}
default:
System.err.println("Unknown locator!");
}
return result;
}
In Scala:
Standard code for waiting (visibility/invisibility)
(new WebDriverWait(remote, 45)).until(
ExpectedConditions.visibilityOf(remote.findElement(locator))
)
Thread.sleep(3000)
More visibility in logs :
while (remote.findElement(locator).isDisplayed) {
println(s"isDisplayed: $ii $a : " + remote.findElement(locator).isDisplayed)
Thread.sleep(100)
}
If you have asynchronous JavaScript processes use web-elements with timestamp:
val oldtimestamp = remote.findElements(locator).get(0).getAttribute("data-time-stamp")
while (oldtimestamp == remote.findElements(locator).get(0).getAttribute("data-time-stamp")) {
println("Tstamp2:" + remote.findElements(locator).get(0).getAttribute("data-time-stamp"))
Thread.sleep(200)
}