Getting class of html cell

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dRosser
Posts: 5
Joined: 14 Aug 2017, 12:10

Getting class of html cell

17 Aug 2017, 16:34

I have accessed a table on a webpage, and I know I can navigate to the right cell on it because I can read the inner text to get the correct value. But I need to care about the class of the cell i'm looking at. Psudo code to follow.

<tr id="row1887">
<td align="center" class="emergency"><div class="txt02" id="available.qty1887">50&nbsp;</div></td>
<td width="32px" align="center" class="bodyrowborder"><div class="txt02">1887</div></td>
<td width="65px" align="left" class="bodyrowborder" ><div class="txt02">&nbsp;Name</div></td>
</tr>

I need to be able to tell when a cell has the "emergency" class. I've tried CurrentRow.cells[0].class and other varriations on that level of access, where CurrentRow.cells[0].innerText will give me 50.

Any tips to get me into the right direction would be appreciated.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Getting class of html cell

17 Aug 2017, 18:10

Does this work?
CurrentRow.cells[0].className
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: Getting class of html cell

17 Aug 2017, 18:21

You can also use classList to get a sort of array and see if the array contains your value you are checking for, in case they have multiple classes. See https://www.w3schools.com/jsref/prop_el ... sslist.asp
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Getting class of html cell

17 Aug 2017, 18:57

Do either of you have any handy code or advice for getting information from tables?

E.g. to grab all the text from a column or table (perhaps tab-separated).
List of countries and dependencies by population - Wikipedia
https://en.wikipedia.org/wiki/List_of_c ... population
Variables and Expressions
https://autohotkey.com/docs/Variables.htm#BuiltIn
Ask For Help - AutoHotkey Community
https://autohotkey.com/boards/viewforum ... rum-search

E.g. you could click to set the active element, or to get the element under the cursor:
Internet Explorer get element under cursor (show borders, show text) (any zoom percentage) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=29458

But I'm not familiar with handling tables. Cheers.

Btw in Firefox, you can do ctrl+drag to select cells in a table.

[EDIT:] I have since found a good way to get text from html tables:
webpages: get table text - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=39131
Last edited by jeeswg on 29 Oct 2017, 12:52, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: Getting class of html cell

17 Aug 2017, 19:21

First isolate the table, then make a list of rows (every tr) and for each for that a list of every column/cell (td) in addition.
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.
dRosser
Posts: 5
Joined: 14 Aug 2017, 12:10

Re: Getting class of html cell

18 Aug 2017, 08:21

currentrow.cells[0].classname Does not work. Unfortunately.
I'll give the class list and getting the td of the cells.

As a side thought do you know if I can getElementByTag on my object that is holding my table rows?
dRosser
Posts: 5
Joined: 14 Aug 2017, 12:10

Re: Getting class of html cell

18 Aug 2017, 08:52

[Solved]
CurrentRow.cells[0].class doesn't work because it was the wrong element call.
CurrentRow.cells[0].className correctly returns the cells class.

Thanks for all the help all.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: coder96, gongnl, Joey5, RandomBoy and 335 guests