Author Topic: Select a specific div on a web page?  (Read 1162 times)

GeorjCostanza

  • Newbie
  • *
  • Posts: 5
Select a specific div on a web page?
« on: July 22, 2020, 09:58:52 PM »
Hi, I'm trying to automate the pressing of a button within a particular div on a web page, but I can't figure out a way.

I also can't use a specific grid reference because the div may move around a bit. Another solution was to count tabs, but for some reason tabbing doesn't select this particular div.

Is there any way to achieve this?

Thanks very much,

Georj

Edit: I should add, this isn't for any malicious purpose. It's an Elite Dangerous process I'd like to automate, like pressing the 'copy system' icon to the right of the system name on pages like this
https://inara.cz/galaxy-starsystem/8007/

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Select a specific div on a web page?
« Reply #1 on: July 23, 2020, 09:43:17 AM »
The data you're looking for is the system name itself? E.G. "Albardhas", in the example page you linked?

While less elegant than a single click, you could copy that same data out of the "SEARCH STAR SYSTEM" field on the right hand side of the page.

Clicking in the field, pressing Ctrl-A to select all text, then pressing Ctrl-C to copy to the clipboard, would have the same end result as pressing the button.

GeorjCostanza

  • Newbie
  • *
  • Posts: 5
Re: Select a specific div on a web page?
« Reply #2 on: July 23, 2020, 07:55:12 PM »
Thanks very much for your reply, I've been learning from your code examples for years!

The actual website isn't Inara, but features a very similar 'copy system' button, and we don't have a field like the 'search star system' on that Inara page example.

The new site in development is currently in beta so I'm not able to post it publicly, but may I send you a PM with the details? No worries if you're too busy

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Select a specific div on a web page?
« Reply #3 on: July 23, 2020, 08:00:39 PM »
Alright, I'll have a look, but I can't make any promises.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Select a specific div on a web page?
« Reply #4 on: July 23, 2020, 09:19:27 PM »
The data that button copies is on screen, and can be reached using the tab key and copied, E.G.
Code: [Select]
Start Loop : Repeat 3 Times
    Press Tab key and hold for 0,01 seconds and release
End Loop
Press Left Shift+End keys and hold for 0,01 seconds and release
Press Left Ctrl+C keys and hold for 0,01 seconds and release
Write [Blue] '{CLIP}' to log

With a left mouse click near the "Show instructions" button (to set the starting point for tabbing), that reliably copies the data on my machine.

GeorjCostanza

  • Newbie
  • *
  • Posts: 5
Re: Select a specific div on a web page?
« Reply #5 on: July 24, 2020, 02:29:00 AM »
Excellent, I'll give that a try when I get home

Thanks for checking it out!

GeorjCostanza

  • Newbie
  • *
  • Posts: 5
Re: Select a specific div on a web page?
« Reply #6 on: July 24, 2020, 06:25:06 PM »
The data that button copies is on screen, and can be reached using the tab key and copied, E.G.

With a left mouse click near the "Show instructions" button (to set the starting point for tabbing), that reliably copies the data on my machine.

Sorry for the delay, only had a chance to check it out now

Unfortunately the screen layout can change a bit depending on options selected, which can add TABable fields to the page. But thank you for the suggestion

I think we're going to have to reconfigure the page to achieve the goal, or go with a joint VA/AHK solution, using the ImageSearch function in AHK

Appreciate your help!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Select a specific div on a web page?
« Reply #7 on: July 24, 2020, 08:01:20 PM »
If you can modify the webpage itself, have you considered adding a keyboard shortcut to it (which should be possible with JavaScript, I believe) that VoiceAttack can send to the browser window, which could trigger copying the data to the clipboard?

GeorjCostanza

  • Newbie
  • *
  • Posts: 5
Re: Select a specific div on a web page?
« Reply #8 on: July 25, 2020, 10:30:09 PM »
If you can modify the webpage itself, have you considered adding a keyboard shortcut to it (which should be possible with JavaScript, I believe) that VoiceAttack can send to the browser window, which could trigger copying the data to the clipboard?

That's a great idea, I'll pass it on to the web dev. When we get it working I'll let you know, and thanks very much for your input