Selenium "Element is not clickable at point" error in Firefox - firefox

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();

Related

Nativescript Android - hide keyboard

In my Nativescript app, the application starts with the login page. On iOS everything looks good, but on android, the username field is focused and the keyboard is showing. Is there a way to prevent this from happening?
So far I have tried:
Getting a reference of another element (a label) and calling lbl.focus() in the page's onLoaded event
getting a reference of the username textfield and calling txt.dismissSoftInput() and txt.android.clearFocus()
None of this worked. Is there another way to hide the keyboard when the page is loaded?
Thank you
I guess the username field is either textview or textfield. If so, try this on loaded callback:
var myTextview = page.getViewById("myTextView");
myTextView.dismissSoftInput();
So I ended up implementing a different solution. This may not be the best approach, but it serves its purpose in my case and I wanted to share it for those of you that face a similar scenario.
in page's loaded event I included this code:
if (page.android) {
var un = page.getViewById('username');
var p = page.getViewById('password');
un.android.setFocusable(false);
p.android.setFocusable(false);
setTimeout(function () {
un.android.setFocusableInTouchMode(true);
p.android.setFocusableInTouchMode(true);
}, 300);
}
The key here is the setTimeout function (Thanks Emil Oberg for pointing me to the right direction). As far as I understand, here is what is happening:
The page loads and we call setFocusable(false) on the only 2 text fields to prevent Android from setting the focus on them
Then we wait 300ms to allow Android to do its initialization
When the timeout executes, call setFocusableInTouchMode(true) to allow the fields to gain focus.
At this point the page is loaded without any fields to be in focus and with the keyboard hidden. If the user taps any of the fields the keyboard will appear and they can proceed to log in as usual.
As I mentioned, this may not be the best, or correct, approach, but works for me. Hope this can save someone the time to research the issue.
You want to clear the focus of the field in the loaded callback:
var searchBar = page.getViewById('my-search-bar-id');
if (searchBar.android) {
searchBar.android.clearFocus();
}
What about combining both tips above?
onClear(args) {
const searchBar = <SearchBar>args.object;
if (isAndroid && searchBar.android != undefined){//avoid random unpleasant error
setTimeout(() => { // the key here was this timeout
searchBar.android.clearFocus();
}, 1)
}
}

How to write an xpath for getting more colors in an web page

How to write an x path for getting more colors in an web page
(for example)This is the web page I am getting two color,for this I need to know how can identify through x path.
(http://www.flipkart.com/comfort-boxer-black-casual-shoes/p/itme84ykdubkghkm?pid=SHOE84YKXF7MXMMK&&sizeSelected=true&otracker=pp_shoe_size )from this page.
Below code work for me:-
driver.get("http://www.flipkart.com/comfort-boxer-black-casual-shoes/p/itme84ykdubkghkm?pid=SHOE84YKXF7MXMMK&&sizeSelected=true&otracker=pp_shoe_size");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
List<WebElement> allOptions = driver.findElements(By.xpath("//div[#class='big selector-paletteImage']"));
System.out.println("Count of colour ="+allOptions.size());
for ( WebElement we: allOptions) {
System.out.println(we.getAttribute("data-selectorvalue"));
}

Scriptaculous Autocomplete list closes on scroll bar click

I have a really annoying issue with Autocomplete with Prototype 1.6. I set up and dialog-style div with a form, which contains an Autocomplete. Everything works fine until I click the scroll bar, or drag it; it closes the list of suggestions. I checked this solution but now I got an javascript error
event.srcElement is undefined
I was checking the controls.js and tried to catch the event object inside the onBlur event, but it travels empty. Printed the offsetX property and is undefined. Looks like the event doesn't exist anymore. either way, it prevents that the list closes but, If I click outside the area, the list now doesn't close. And that's kinda of issue too
Anyone with this same issue? Any idea?
Thanks in advance
I was having the exact issue yesterday, but after doing some r&d I got a pretty handy fix for this.
By default this script was hiding the result div (Suggestion List) on the blur event on the search text box so as soon as we click on result div's scroll bar focus gets lost from input element & result div closes. So I did a small edit in controls.js to change the behavior of script, so now result div close method doesn't invoke on blur (focus out) from input element but triggered on the click on the document except the text input element.
For your convenience I've put the edited controls.js here.
If you like to know what has changed in JS file, here it is;
Added a event listener to the document. Just below this line
"Event.observe(this.update, "keypress", this.onKeyPress.bindAsEventListener(this));"
Event.observe($(document), "mouseup", this.onMouseup.bindAsEventListener(this));
Added a new onMouseup method.
onMouseup: function(event) {
if(!this.hasFocus) {
this.hideTimeout = setTimeout(this.hide.bind(this), 250);
this.hasFocus = false;
this.active = false;
}
},
Modify the onBlur method (Comment out two line in block)
onBlur: function(event) {
//this.hideTimeout = setTimeout(this.hide.bind(this), 250);
//this.active = false;
this.hasFocus = false;
}
I hope this will solve your issue.
Thanks
Vinod Kumar

How to test AjaxEventBehavior("onClick") for Apache Wicket radio button?

I'm using apache wicket and I run into trouble regarding testing the AjaxEventBehavior for a Radio button. Actually I want to test the "onClick" event like in my case when I select/click a radio button from a RadioGroup a specif page is rendered.
Code snippet:
RadioGroup<Boolean> selectPageRadioGroup =
new RadioGroup<Boolean>("selectPageRadioGroup", new Model<Boolean>(Boolean.TRUE));
selectPageRadioGroup.setDefaultModel(new Model<Boolean>(Boolean.TRUE));
final Radio<Boolean> radioButton1 =
new Radio<Boolean>("radioButton1", new Model<Boolean>(Boolean.FALSE));
radioButton1.add(new AjaxEventBehavior("onclick") {
#Override
protected void onEvent(AjaxRequestTarget target) {
setResponsePage(MyWebPage.class);
}
});
selectPageRadioGroup.add(radioButton1);
Assuming you have already done
WicketTester tester = new WicketTester();
tester.startPage(PageContainingRadioButton.class);
or a similar startPanel (Wicket 1.4) or startComponent (Wicket 1.5), so that your test has rendered a page containing the button at a known path you should be able to make WicketTester simulate the ajax behavior by something like
tester.executeAjaxEvent("blabla:form:selectPageRadioGroup:radioButton1", "onclick");
(You'll need to adjust that path of course.)
and then check that it did the right thing with
tester.assertRenderedPage(MyWebPage.class);

How to get tab in TabOpen event with Firefox FUEL?

I'm writing a firefox extension and really need to listen on TabOpen events and get some details about tab that was opened. But I can't figure out how do I get an actual tab from event object that my callback receives. Is it somewhere in event.data? Is there a way to inspect this object?
Some code that I have tried so far but it doesn't work:
Application.activeWindow.events.addListener("TabOpen",
function(event) {
Application.console.log("TabOpen");
var tab = event.data.target;
Application.console.log(tab.uri);
}
);
In your code, event.data will give you a BrowserTab object. If you want the current URI of the tab, you'd want tab.uri.spec for the string version, or just tab.uri if you want an nsIURI object.
here is an example from the MDC but without using FUEL:
// add event listener
var container = gBrowser.mPanelContainer;
container.addEventListener("DOMNodeInserted", exampleTabAdded, false);
function exampleTabAdded(event)
{ // listening for new tabs
if (event.relatedNode != gBrowser.mPanelContainer)
return; //Could be anywhere in the DOM (unless bubbling is caught at the interface?)
var browser;
browser = event.target.childNodes[1];
// browser is the XUL element of the browser that's been added
}
I've added some new content to MDC that should help with this; information on how to pull the tab object out of the TabOpen event is now available in the example here:
https://developer.mozilla.org/En/FUEL/Window
Also did some other cleaning up while I was at it. Hopefully this will help (especially once the search index refreshes).

Resources