Selenium (RSelenium) giving StaleElementReference clicking an element just recently searched - r

I'm trying to get some Selenium tests against Shiny app that has some notifications. I have a following function I would call to close all notifications that are there, and the reference to the element is fetched just before the click is called.
close_notifications <- function() {
buttons <- remDr$findElements(using = "xpath", "//[#id='shiny-notification-panel']///div[contains(text(),'×')]")
close_function <- function(btn) {
btn$clickElement()
}
lapply(buttons, close_function)
}
However when there is a notifcation visible in the app and I try to call it, I'll get the following error regarding it.
Error: Test failed:
* Summary: StaleElementReference
Detail: An element command failed because the referenced element is no longer attached to the DOM.
class: org.openqa.selenium.StaleElementReferenceException
What might be the reason I'm getting this error, even when the reference is fetched just before trying to click the button? Notification duration itself is quite long so it doesn't disappear in the UI even when I get the StaleElementReference. I'm not sure if Shiny changes something under the hood so that it's not the same DOM element, however, I guess that shouldn't be the case when I'm trying to press the button just after looking it up with the Selenium driver.

Related

how to access dropdown selection in Cypress, get error: element is detached from the DOM

I am trying to select a dropdown item using Cypress. When i use the Cypress's Open Selector Playground, and point at the Web Element, i get cy.get('.Dropdown-placeholder').type('Name')
I get an error:
CypressError
Timed out retrying: cy.type() failed because this element is detached from the DOM.
<div class="Dropdown-placeholder"></div>
Cypress requires elements be attached in the DOM to interact with them.
The previous command that ran was:
> cy.get()
This DOM element likely became detached somewhere between the previous and current command.
Common situations why this happens:
- Your JS framework re-rendered asynchronously
- Your app code reacted to an event firing and removed the element
You typically need to re-query for the element or add 'guards' which delay Cypress from running new commands.Learn more
and when i try to get the CSS Selector for the actual Entry, i get:
cy.get(':nth-child(3) > #Question > .Dropdown-root > .Dropdown-control > .Dropdown-placeholder')
when i try cy.get('.Dropdown-placeholder').focus().type('Name')
I get Error:
cy.focus() can only be called on a valid focusable element. Your subject is a: <div class="Dropdown-placeholder"></div>
and for: cy.get('.Dropdown-placeholder').click().type('Name')
i get error:
CypressError
Timed out retrying: cy.click() failed because this element is detached from the DOM.
<div class="Dropdown-placeholder"></div>
Cypress requires elements be attached in the DOM to interact with them.
The previous command that ran was:
> cy.get()
This DOM element likely became detached somewhere between the previous and current command.
Common situations why this happens:
- Your JS framework re-rendered asynchronously
- Your app code reacted to an event firing and removed the element
You typically need to re-query for the element or add 'guards' which delay Cypress from running new commands.Learn more
And here is the HTML:
<div class="Dropdown-root module-Questions-module-dropDownContainer--2bcD7--"><div class="Dropdown-control" aria-haspopup="listbox"><div class="Dropdown-placeholder is-selected">Name</div><div class="Dropdown-arrow-wrapper"><span class="Dropdown-arrow"></span></div></div></div>

Error on calling enterVR() on a-scene (chromium and nightly desktop)

I have been having issues when trying to call enterVR() on my a-scene element from within my JS code. Whether I wait for the scene to have loaded or bind enterVR() to a vive controller input, I get the following error:
Error: Failed to enter VR mode ('requestPresent'): API can only be initiated by a user gesture.
I have been using the latest chromium experimental build as well as Mozilla Nightly and the following Aframe version(master) :0.5.0 (Date 22-03-2017, Commit #bc6be7c).
Ultimately, my only goal is to begin presenting content to the headset as soon as the scene has loaded.
As the error message says, you need a user gesture like a click to enter VR. If you do it within a 'window.addEventListener('click', ...)', it should work

Switch button using paper js not work

I'm trying to make a simple image editor using canvas. My code is here http://jsfiddle.net/qrd3muyh/.
How to make the switch button to work? If I run it in my localhost, I got these error when clicking the button pencil : Uncaught TypeError: undefined is not a function
And when clicking the circle button : Uncaught ReferenceError: myCircle is not defined.
Why does it happen and any clue to solve it? Many thanks before..
The reason for this is because all PaperScript tags become a scoped object (referred to as a PaperScope). The reason you are getting the undefined error is because the jQuery callback function has no reference to myCircle, etc.
To resolve this, you should access the currently active paper scopes via the paper object.
$('#pencil').on('click', function(){
console.log(paper.tools); # See how many tools are in your paper object
paper.tools[1].activate(); # Activate one of them.
});
$('#circle').on('click', function(){
paper.tools[0].activate(); # Activate the other.
});
To get the currently active tool, you can do this:
$('#pencil').on('click', function(){
var current = paper.tool; # Access currently active tool.
current.remove(); # remove this tool
});
Here is some good reading about the PaperScopes.

Flex: PopUpManager giving "...null object reference" error

I have a main application calling several ViewStack states, each with popup windows. If I don't open any popup windows, I can move between states fine. If I open a popup window then try to change the state using currentState=... I get the error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at spark.components::Scroller/focusInHandler()[E:\dev\4.y\frameworks\projects\spark\src\spark\components\Scroller.as:2139]
at flash.display::Stage/set focus()
at mx.core::UIComponent/setFocus() [E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:9905]
...
I see others having the same problem, for example here:
http://forums.adobe.com/thread/1031531
http://forums.adobe.com/message/2767130
http://forums.adobe.com/message/3448443
http://forums.adobe.com/thread/655749?tstart=-1
http://forums.adobe.com/thread/801149
http://flex4examples.wordpress.com/2011/05/05/skinnabletextbase-focusmanager-runtime-error-popup/
http://bugs.adobe.com/jira/browse/SDK-32036?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel
But I haven't figured out how to implement the recommended solution. It sounds like I should just include:
import mx.managers.PopUpManager; PopUpManager;
inside my main application and it should work, but it doesn't work for me.
My application has each view state in a different file, each defined using <views:View>. Also, all of the popups are separate files defined as <s:TitleWindow>. Each file includes this line:
import mx.managers.PopUpManager;
I wonder if this means each file is using a different popup manager(?), when it's a singleton and only one should be used for the whole app (how to set that up?).
The code I use to call a popup is:
var _popupName:MyTitleWindowFileName = MyTitleWindowFileName(
PopUpManager.createPopUp(this, MyTitleWindowFileName, true));
_popupName.addEventListener(MyAppController.CLOSE_POPUP,onClosePopUp);
PopUpManager.centerPopUp(_popupName); // call popup
Note that when the main application (the one defined as <s:Application>) runs, the ViewStack states have not been loaded yet (since they get loaded when they are used the first time). Not sure if that has any cause/effect here.
I've tried to follow Adobe's example code in the "Passing data to and from a Spark pop-up window" section here:
http://help.adobe.com/en_US/flex/using/WS6c678f7b363d5da52e8f1ca1124a0430dcf-8000.html#WS6c678f7b363d5da52e8f1ca1124a0430dcf-7ffe
Any ideas much appreciated.
Based on your comments, it seems like the error occurs because the focus remains in the popup. I would expect the PopUpManager and FocusManager classes to handle this better.
One thing I can think of is that the FocusManager may be trying to handle this. But since the state changes, the item that originally had focus (in the view stack child, before the pop up was opened) may no longer be there when the view state changes. Just a hunch, w/out seeing your code.
Here's some things you can do to either work around the problem (or better) further debug it to understand what is happening:
Use FocusManager.setFocus() to move the focus back to an object in the view stack child before closing the pop up
Use FocusManager.getFocus() to debug and see where it thinks the focus is at various stages (before opening popup, before/after changing state, and before/after closing pop up).
It appears this is the situation I'm experiencing:
Adobe Air: scroller throws error when changes focus between different applications
It's an Adobe bug. Solution from Adobe is:
This bug is easily fixed by changing Scroller to do a null pointer check on focusManager before using it.
which is what the first link above attempts to do.
Another link: http://forums.adobe.com/message/3812805

Error / Validation / ToolTips in Adobe Flex

Is there any code or custom options available to achieve the following :
1> When an error occurs in a text box, the validation shows the error. Forces the user to remove the error and only then proceed to complete remaining text inputs. KEEPS the mouse focus on the Text Box.
I have used built in mx:Validator tags, but it does not coerce the user to remove the error. Instead, user can easily go ahead without rectifying the error.
2> Can the error message which generally appears as a tooltip when mouse focus moves over the text input with the error, REMAIN until the user removes error and not just be displayed on mouse hover action?
You can customize your ToolTips to show your Error. Check this link to customize your tooltip, to show your error in ToolTips
For #2, check out http://aralbalkan.com/1125.
Unfortunately, it is a lot of hassle if you have multiple/large forms. It is unfortunate flex doesn't provide more styling options for the error tooltip.
#1 seems to be a bad UI design. While you may not allow them to submit a form unless they enter valid information, they should be able to navigate around the form freely and fill in the information as they choose. Just my opinion.
A solution to question 1) is as follows;
Use the Validator.validateAll static method to check that all form items are valid before allowing the form to be submitted. The following snippet is taken from a good flex example which shows this
private function resetForm() :void
{
btnLogin.enabled = false;
}
private function validateUs() :void
{
btnLogin.enabled = (Validator.validateAll([val1,val2]).length == 0);
}
The complete example is here
http://idletogether.com/easy-form-validation-and-submit-button-enable-disable-in-flex-3/

Resources