I am by no ways a developer. I get by by google, but this issue has a depth I do not understand.
If you can explain what I am lacking in programming knowledge it'd be appreciated.
With powershell I can get all .Text from whatever div I choose. However I cannot figure out how to find the Text from a within a div whose .Text is "abc"
$allGames.Text contains all the game titles, so far so good:
[System.Reflection.Assembly]::LoadFrom("{0}\WebDriver.dll" -f $PathToFolder)
if ($env:Path -notcontains ";$PathToFolder" ) {
$env:Path += ";$PathToFolder"
}
$ChromeOptions = New-Object OpenQA.Selenium.Chrome.ChromeOptions
$ChromeOptions.AddArgument('start-maximized')
$ChromeDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver($ChromeOptions)
$ChromeDriver.Url = $uri
#sometimes site is slow, 5s should be enough
Start-Sleep -Seconds 5
$allGames = $ChromeDriver.FindElementsByCssSelector("div.result-title.gameName")
And inside that is a whose Text I want to retrieve. Neither names of the nor is unique. There's hundreds of divs and spans with the same name. So I can't access them directly.
I only want the text from the span, if its div has the text "abc"
The rudimentary knowledge I have with powershell tells me to do this
foreach ($game in $allGames) {
$game.GetType() #=RemoteWebElement
if ($game.Text -eq "abc") {
Write-Host "Found something!"
$span = $game.FindElementsByCssSelector("span.search-listing-count-text")
$span.Text
}
}
However $span contains nothing
I don't understand if I'm failing at understanding Selenium (which I don't even know what it is. Google told me I could use it to find stuffs on sites) or if I'm failing to understand the object oriented aspects of powershell (which I don't :))
What am I missing?
The html snippet:
<div class="search-results">
<div class="result-title gameName">abc
</div>
<div class="result-info">
<span class="search-listing-count-text">123
</span>
</div>
</div>