QuerySelector CSS selector changes according to variable value Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
zayntheboss
Posts: 14
Joined: 24 Feb 2019, 15:21

QuerySelector CSS selector changes according to variable value

22 Apr 2019, 15:46

Hello

Could someone please help me? I'm trying to change the value of my CSS selector based on the value of the variable "num"

Code: Select all

msgbox % pwb.document.querySelector("#course-list-items > div:nth-child("num") > div > a").InnerText
but I keep getting an error that num" is an illegal character. Can someone please help?!
A_AhkUser
Posts: 1076
Joined: 06 Mar 2017, 16:18
GitHub: AAhkUser
Location: France

Re: QuerySelector CSS selector changes according to variable value  Topic is solved

22 Apr 2019, 17:23

Just as in the theory of formal languages the dot (.) is used to concatenate subsets of charactersin ahk.
The dot operator is a binary operator and to distinguish it from the object access (ibid.) one (e.g. document.title), there must be at least one space on each side of the period:

Code: Select all

a . b
where a and b should evaluate to strings. In an sub-expression (like a function parameter), literal strings enclosed in double quotes automatically evaluate to strings - as you already correctly done in your example.
The following should work:

Code: Select all

msgbox % pwb.document.querySelector("#course-list-items > div:nth-child(" . num . ") > div > a").InnerText
[EDIT] 1000th post :!:
swagfag
Posts: 3273
Joined: 11 Jan 2017, 17:59

Re: QuerySelector CSS selector changes according to variable value

22 Apr 2019, 18:14

at least 1 space(2, on either side, being recommended) is required after num for this to parse correctly, ie ...th-child("num ") > di...
or be explicit and use dot concatenation

Return to “Ask For Help”

Who is online

Users browsing this forum: Alexzemm, Chunjee, enrica, jmasiak, jNizM, sdkyron and 233 guests