Jump to content

_WD_FindElement - use of $sStartNodeID?


Recommended Posts

I am trying to search for an element, starting at the prior element that I just found.  It seems I should be using the $sStartNodeID, but can't seem to get it to work.  I was assuming that what should be used for the $sStartNodeID would be the returned value from the prior element search.  This may not be correct, but cannot find the answer via any forum or google searches.

Just need some direction on where to find an example or info on this please.

Thanks

 

Link to comment
Share on other sites

Taking off the "" did not make any difference, however, I think I now have a clue as to why no elements are found with tagname "a".  When the script stops after the command fails to find any elements, the URL is still up.  When I go to tools and inspect the starting element, and then look at the HTML below (where it should be finding elements with tagname "a", there are none showing.  When I use the dropdown arrows on the left the elements I'm looking for become visible.  Seems only "visible" elements are found.

Is there a way to force all the page HTML to be visible?

 

Link to comment
Share on other sites

1 hour ago, dgendrud said:

Taking off the "" did not make any difference

Technically, it did by solving the problem where _WD_FindElement was returning the error Unknown Command.

Quote

When I use the dropdown arrows on the left the elements I'm looking for become visible.  Seems only "visible" elements are found.

I'm not sure which dropdown arrows you are referring to here. Please clarify.

Link to comment
Share on other sites

Yes, solved the Unknown cmd issue, now just a no match issue.  I suspect the no match is because the html that exists on the page, just below the "$sStartNodeID element" , is not expanded so the elements I am searching for are not visible.  When I use the Firefox  web developer tool and inspect I can only see the "row elements"  I can use the down arrows on the left of the html elements to show the elements I am searching for.  Cannot find any command to solve this yet.  Maybe, I need to use the _WD_GetSource($sSession) command and search that?  Maybe there is a more straightforward way?

I'm working it, but any guidance is appreciated,

Thanks

 

Link to comment
Share on other sites

@dgendrudLet's try this another way because your last post didn't help me understand the situation any better.

I've run your script and also examined the website in the browser's Dev Tools. This code --

;Get the link element - There appears there is only one element due to the XPath locator used (link by text did not seem to work)
    ;This XPath find now seems to work and return a value
    Local $aFirstTkr = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/main/article/div/div[1]/table/tbody[1]/tr[1]/td[1]/a", DEFAULT,DEFAULT)

finds the first link in the table's symbol column. This was "ADM" for me. BTW, this xpath could be shorted to "//table/tbody/tr/td/a".

Is this the correct element that you are trying to locate? Since it doesn't have any children, it can't be used as the starting node in subsequent lookups. I'm still not clear which down arrows you are talking about. This is what the top section of the table looks like for me --

image.thumb.png.268d21d779e8e356d2405c1221e67718.png

Link to comment
Share on other sites

OK, thanks again.  These comments help, I'm going to work this some more.  This URL page has about 40 stock symbols.  I am trying to access them all and get them into an array.  I'm thinking of looking at some of the Frame commands.

 

Link to comment
Share on other sites

16 minutes ago, dgendrud said:

I'm thinking of looking at some of the Frame commands.

Why? Those are only beneficial if there are frames involved.

Quote

This URL page has about 40 stock symbols.  I am trying to access them all and get them into an array. 

There are multiple ways to achieve this. You could use _WD_GetTable, which should produce an array containing the entire table's contents. You could also do something like this (untested) --

Local $aLinks = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//table/tbody/tr/td/a", Default, True)
Local $iCount = UBound($aLinks)
Local $aSymbols[$iCount]

For $iIndex = 0 To $iCount - 1
    $aSymbols[$iIndex] = _WD_ElementAction($sSession, $aLinks[$iIndex], "Text")
Next

_ArrayDisplay($aSymbols)

This could also be accomplished with a single call to _WD_ExecuteScript to gather the desired information using Javascript.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...