Rselenium error 'An element command failed because the reference element is no longer attached to the DOM' - rselenium

I am trying to scrape the following page:
https://www.dukascopy.com/swiss/english/marketwatch/sentiment/
specifically, the numbers in the 'span' tag, the percentages in the green and red bars. i am using rselenium and my code is the following:
checkForServer()
startServer()
remDr<-remoteDriver$new()
remDr$open(silent = TRUE) #opens a browser
remDr$navigate("https://www.dukascopy.com/swiss/english/marketwatch/sentiment/")
webElems <- remDr$findElements(using = 'css selector', "span")
#pretvorim v tekst
resHeaders <- unlist(lapply(webElems, function(x){x$getElementText()}))
it works until the last line, where i receive the error:
An element command failed because the referenced element is no longer attached to the DOM
what is wrong?

Related

I am facing error in this code. cells is showing red in deveper sources

`selectedRow.cells[0]. innerHTML = formData.fullname;
my error is can not read property of null(reading cells)
`

extjs grid sort error - still works but errors in console window

I have an ExtJs grid, when I click sort, it does in fact sort the grid, but in the console window I get error messages.
Uncaught TypeError: Cannot read property 'isSynchronized' of undefined
at constructor.addCls (ext-all-rtl-debug.js?_dc=1487248312797:34688)
at constructor.addCls (ext-all-rtl-debug.js?_dc=1487248312797:63226)
at constructor.disable (ext-all-rtl-debug.js?_dc=1487248312797:63902)
at constructor.callParent (ext-all-rtl-debug.js?_dc=1487248312797:11709)
at constructor.disable (ext-all-rtl-debug.js?_dc=1487248312797:123642)
at constructor.ddDisable (ext-all-rtl-debug.js?_dc=1487248312797:175799)
at constructor.handleMouseDown (ext-all-rtl-debug.js?_dc=1487248312797:134260)
at constructor.handleMouseDown (ext-all-rtl-debug.js?_dc=1487248312797:138266)
at constructor.callParent (ext-all-rtl-debug.js?_dc=1487248312797:11709)
at constructor.handleMouseDown (ext-all-rtl-debug.js?_dc=1487248312797:139491)
I also get the following error on startup... not sure if its related

How to get all elements' text attribute at once in Robot Framework?

I have some web elements which has the same prefix for their ID attribute. I can get these elements all at once with get webelements; I want to extract their text attribute with one command. I have wrote this line:
${elList} = get webelements xpath=//*[starts-with(#id, '${formName}:${row}')]
${rowList} = evaluate [item.get_attribute('text') for item in ${elList}] selenium
Which returns:
Evaluating expression '[item.get_attribute('text') for item in [<selenium.webdriver.remote.webelement.WebElement object at 0x7f7b6c5f09d0>, <selenium.webdriver.remote.webelement.WebElement object at 0x7f7b6c5f0990>]]' failed: SyntaxError: invalid syntax (<string>, line 1)
I can't understand the problem here; BTW I'll appreciate any other solution for my issue.
EDIT1: I also have tried below code:
${elList} = get webelements xpath=//*[starts-with(#id, '${formName}:${row}')]
:FOR ${item} IN #{elList}
\ log to console ${item.get_attribute('text')}
But the console just shows None; it is the same for ${item.get_attribute('value')}.
I've solved this; I found this answer and used ${item.get_attribute('innerHTML')} as a try. It worked pretty fine.
you could use this also.
#{elem} = Get WebElements css=._1vC4OE._2rQ-NK
:FOR ${item} IN #{elem}
\ log to console Item: ${item.text}
Is text an actual attribute or just the containing text? If it is an attribute then perhaps you can try the following method.
${count}= Get Matching Xpath Count //*[starts-with(#id, '${formName}:${row}')]
${rowList}= Create List
:FOR ${i} IN RANGE ${count}+1
\ ${text}= Get Element Attribute xpath=(//*[starts-with(#id, '${formName}:${row}')])[${i}]#text
\ Append To List ${rowList} ${text}

Why isn't the Mouse.DoubleClick functioning properly when the Coded UI test is executed via MTM?

What I'm trying to is to double click on a row in a WPF datagrid. To achieve this I'm using the following code:
WpfTable invoiceList = new WpfTable(base.MainWindow);
invoiceList.SearchProperties.Add(WpfTable.PropertyNames.AutomationId, "datagridID");
invoiceList.WaitForControlReady(15000);
Mouse.DoubleClick(invoiceList.GetRow(0));
When I run this on my machine the test passes but when I run the same test via MTM I get the following error:
Test method
org.Application.Automation.TestCases.CommentsTests.VerifyExistingCommentsTest
threw exception:
Microsoft.VisualStudio.TestTools.UITest.Extension.PlaybackFailureException:
Cannot perform 'DoubleClick' on the control. Additional Details:
TechnologyName: 'UIA' ControlType: 'Row' FrameworkId: 'WPF' --->
System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has
been returned from a call to a COM component.
Could someone point in the right direction as to how I could fix this?
In case anyone else is facing this issue, I changed my code to the following to get it to work.
WpfControl row = invoiceList.GetRow(0);
row.WaitForControlReady();
Mouse.DoubleClick(new System.Drawing.Point(row.BoundingRectangle.X + row.BoundingRectangle.Width, row.BoundingRectangle.Y + row.BoundingRectangle.Height/2));
So instead of double clicking on the WpfRow object, I used the Mouse.DoubleClick(new System.Drawing.Point()) option and passed center point (i.e System.Drawing.Point) as the parameter. As to why the previous approach didn't work, I'm afraid I cannot explain.

Getting javaScript code from a script tag using Selenium: Is that possible?

I'm getting an error from the last line of the code below
// Scala code
val driver: HtmlUnitDriver = new HtmlUnitDriver()
val el = driver.findElementByXPath(xp)
val js = el.getText()
the "el" element returned is a "script" tag. I was wondering if is possible or not to get the content of the tag using .getText()
Here's the error
Exception in thread "main" java.util.NoSuchElementException: None.get
Yes u can get the content of a script by using attribute like this el.getAttribute("innerHTML");
As far as i can see, it is not possible to access the content of a "script" element using XPath. The solution I found to this issue was to apply a regular expression on the HTML source:
// Scala code
val regex = "your (pattern)".r
val res = ( regex findFirstMatchIn driver.getPageSource() ).get group 1

Resources