Unable to evaluate the expression Object has been collected - selenium

There is one object from one class which is not getting identified during the runtime or debugging.
The same object gets highlighted on devtools. I'm not understanding what is wrong over here.
Does anyone have any idea what is the cause of this issue?
Let me know if require more details.

The reason it was not getting highlighted during runtime was because it is the part of one iframe. After pointing my webDriver to the iframe and then the object , my code was running successfully.

Related

EXCEPTION: stale element reference: element is not attached to the page document

My HTML-Page contains (among other stuff) this bit:
<ol id="links">
<li id="links_1">stackoverflow</li>
</ol>
In my code to test the page, I then do:
el←FindElementById'links_1'
(ACTIONS.MoveToElement el).Build.Perform
and this crashes with
EXCEPTION: stale element reference: element is not attached to the page document
(Session info: chrome=81.0.4044.129)
However, this error doesn't seem to be justified, as the element is still alive:
el.Displayed
1
el.Text
stackoverflow
el.Location
{X=56,Y=282}
How can I fix this problem?
(The environment is APL. I've left out a few APL-details here because I feared they might be avoidable "distraction" from the core-issue)
During my research before posting, I saw the question stale element reference: element is not attached to the page document but it doesn't seem to apply:
as shown, I'm doing the FindElementById and access it immediately after finding it. The DOM doesn't change, page is static.
explanations about it no longer being part of the DOM do not apply: it is found and, as I attempted to show, I can access properties such as Displayed or Text.
I also went through the reference, but this explanation did not help.
Also, there is no looping going on and nothing changes the page. It's really straightforward: GoToUrl * Find * MoveToElement.
I removed the chromedriver-tag, as I can repro this with Firefox and geckodriver. However, with geckodriver, I get "EXCEPTION: Web element reference not seen before:" when I do MoveToElement - but I can do el.Click and access its properties in exactly the same way that as with Chrome.
Update: a coworker investigated this a bit deeper (beyond my comfort zone) and found that before throwing this "stale exception", there is (I'm not sure how to word this properly and where exactly it occurred) a 404-exception. I just know 404 as an HTTP Status-code - that's all it means to me. But clearly the browser was not asked to navigate anywhere, so I can't be related to an HTTP404. Does that perhaps ring some bells with anyone more familiar with the internals of WebDriver?
This was a complex and multi-layered problem, but when I finally removed all layers - it worked!
The key-factor which caused this problem:
due to a fault in the way I had written the test caused it to be executed twice - and the 2nd run always exposed the problem.
I had instantiated ACTIONS in the test-framework and was not aware of a critical feature: it continuously builds a chain of actions, any Build.Perform..-steps just added to that. Solution: create separate instances of every run (possibly, since it's fairly lightweight) or call ACTIONS.Reset(requires WebDriver4). I've never had issues with WD4 (although it still is in alpha) - but this gave the ultimate reason to switch!

When invoking js.exec in Geb/Spock, the exec method is flagged as 'null'

I am creating a suite of tests (using Geb/Spock) for a web site. In one of them, the element I want to access is on the top of the page, so, to make sure that is visible, I want to scroll to the top of the page.
The command I am using is:
browser.js.exec('window.scrollTo(0, 0);')
or variations of it like
js.exec('window.scrollTo(0, 0);')
or other alternative like:
js.exec('window.scrollBy(0, -250);')
None of them makes the page scroll up, and when executing I get the following error (it is the only error, no other feedback). The error message using the other options listed above is identical (other than the command itself):
Condition not satisfied:
browser.js.exec('window.scrollTo(0, 0);')
| | |
| | null
| geb.js.JavascriptInterface#4019094f
geb.Browser#3dcac33e
at UserCreatesCompany.Go to Home Page and click on the log to
GitHub button as user User1(UserCreatesCompany.groovy:170)
I can not interpret the message that 'exec' is null. What exactly it means?
To make things more interesting, at the end of this script I am running the following cleanup procedure
js.exec('window.scrollTo(0, document.body.scrollHeight);')
DeleteButton.click()
$("button",'data-automation-id':"button-modal-yes").click()
}
and that works well: the page scrolls down. So, does not seem a problem about some missing library.
Any suggestion of what I may be doing wrong?
The version of the different components I am using is:
groovyVersion = '2.5.4'
gebVersion = '2.3'
seleniumVersion = '3.141.59'
chromeDriverVersion = '2.45'
First of all, you should not need to ever manually scroll the page to make elements visible - Selenium WebDriver which is underpinning Geb will do that for you automatically as soon as you start interacting (clicking, setting value, etc) with content.
Secondly, the failure you are getting is a failed assertion coming from a statement in an automatically asserted (then: or expect:) Spock block. It feels to me that you don't understand a concept which is core to Spock and therefore you should read about it in the manual first. It should make the failure you're getting clearer.
Thanks for the answer. Clearly: I was not fully aware of the different constrains the different blocks impose on what is executable or not. The manual is pretty clear once you have stumbled!
I am intrigued by your first assertion pointing that Selenium WebDriver will move to the element as soon as I interact with it. That was my understanding but it was not working. I made sure the element in question had a unique identifier, but still, it was not able to found it if the element had to be found by scrolling up. On the other hand it worked smoothly when locating the element WebDriver scrolled the page down.
Thanks again for the explanation. I have learn something new today!

Issue in using dynamic XPATH in selenium

I have written the below code to identify the element in chrome and click on it, but later I realized that value for "#id" (u_jsonp_X_x) is keep on changing and that's causing fail to identify the element.
dr2.findElement(By.xpath("//*[#id='u_jsonp_2_4']/div/a[3]/span[1]")).click();
To resolve this issue, I have used below code based on my understanding but still not working
dr2.findElement(By.xpath("[starts-with(#id=(),'u_jsonp_2')]")).click();
Could you please help me to resolve this issue?
The XPath syntax in the second case is not correct, you meant:
dr2.findElement(By.xpath("//*[starts-with(#id, 'u_jsonp')]/div/a[3]/span[1]")).click();

UFT/QTP - Can not find Objects parent

I can not access an object in my testcase.
The object is a Tab, attached to a (Sub)Window in my application.
Befor and after the Testcase the Tab and the window the tab is attached to is found by the object spy fine, but while the testcase runs the Error below comes up .
Cannot find the "[ActiveX]" object's parent "[Window]" (class Window). Verify that parent properties match an object currently displayed in your application.
I access the object so :
VbWindow("ApplicationWindow").Window("SubWindow").ActiveX("Tab")
I am new to UFT, so I searched a while and found some solutions but they seem not to work for me, because they always related to browser testing, not application.
Warning: Long explanation follows, you can skip to the last paragraph for a suggested quick win.
When UFT identifies objects it does so from the top down, your object hierarchy is:
VbWindow("ApplicationWindow").Window("SubWindow").ActiveX("Tab")
And UFT said that:
Cannot find the "[ActiveX]" object's parent "[Window]" (class Window).
This means that id did find VbWindow("ApplicationWindow") but could not find the Window("SubWindow"). Try highlighting the VbWindow to make sure that UFT is identifying the object you expect. Then use the object spy to inspect the window you think UFT should find. Then compare the properties in the object repository to those of the window you see and find how these descriptions differ.
As a shortcut you can try using Maintenance Run Mode which should do these steps for you and suggest a way to fix the test.
Just a thought to identify the root cause of the problem.
1.Try with the top level container(skipping the next level container) and check your existence of parent.
VbWindow("ApplicationWindow").ActiveX("Tab")
2.Check the properties before and after. I meant side by side validation. There could be the chance of property mismatch.
3.Use Refresh Object method.
Window("Calculator").RefreshObject
4.Query your parent from the Tab object
Set objParent = VbWindow("ApplicationWindow").ActiveX("Tab").GetTOProperty("parent")
Msgbox objParent.GetROProperty("text")
Set objParent = VbWindow("ApplicationWindow").Window("SubWindow").ActiveX("Tab").GetTOProperty("parent")
Msgbox objParent.GetROProperty("text")

geb jquery.mouseover() not working

The geb documentation shows that it has built in jQuery support. Im interested in one particular method called mouseover. However when I try to use the mouseover function I get a warning saying, "Cannot resolve symbol 'mouseover'". This happens even when I'm using the code in their example. What am I missing?
This might not directly answer your question. But if you are trying to mimic mouse over action in Geb, you could also use
interact {
moveToElement(element)
}
http://www.gebish.org/manual/current/#interact-closures