Chrome.AHK - Scraping browser data returns value in console, but returns null in AHK script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kyorun
Posts: 1
Joined: 01 Jun 2023, 18:18

Chrome.AHK - Scraping browser data returns value in console, but returns null in AHK script

Post by kyorun » 01 Jun 2023, 18:55

I'm trying to scrape Brave browser data using a modified version of the Chrome.ahk library and I'm running into an error where the returned value when scraping via AHK script is undefined, but the returned value when scraping via browser console is the actual value (1855.0)

This is the HTML that I see when using Inspect. I am trying to scrape the float value from the most nested div (1855.0):

Code: Select all

<div class="react-grid-item react-draggable cssTransforms react-resizable" style="z-index: 2; width: 1080px; height: 76px; position: absolute; transform: translate(0px, 44px);">
	<div name="subheader" class="css-uv33rk">
		<div class="ticker-wrap css-17aqogg">
			<div class="css-1zojt0">
				<div class="css-4cffwv">
					<div class="css-1e07uyp">
						<div>...</div>
						<div>...</div>
						<div data-bn-type="text" class="draggableHandle css-h7bxua>
							1855.0
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
This is my current code in AHK for testing. Running this code returns a 'Cannot read properties of undefined' error:

Code: Select all

#NoEnv
#SingleInstance, force
#include, C:\...\Brave.ahk

page := brave.getpage()
url := "https://pro.apeswap.finance/"

F3::
;page.Call("Page.navigate", {"url": url})

CurrentPrice := page.Evaluate("document.getElementsByClassName('draggableHandle css-h7bxua')[0].innerText").Value
MsgBox, %CurrentPrice%

Exit
If I run the same exact JS command in the browser's console, I get the proper value back:

Code: Select all

document.getElementsByClassName('draggableHandle css-h7bxua')[0].innerText
> '1855.0'
Is there something I'm missing? I know that the Evaluate command in my script is returning the error, but I can't figure out how to fix it.

Return to “Ask for Help (v1)”