0

I am trying to navigate through a webpage using just my keyboard. Through the use of my tab key I can enter in data into several input boxes, and press several submit buttons.

However I run into a problem when trying to set focus to an image element on the page. For some reason it does not allow me to select it with the tab key. I can click on it with my mouse and then a popup appears but this really slows down efficiency.

I have considered creating a script in VBA to do this but right now I would prefer a quick-fix without having to spend hours developing a macro.

NOTE: I did quickly try to assign the reference to the <img> element and use the Click and Focus methods in VBA but that didn't work. I don't get an error, the code runs fine but nothing happens on the webpage. This leads me to think that this will be a bigger project than it appears, hence my reluctance to go down that path.

I did a bit of research and it seems that tabindex is not supported by the <img> element. Does that mean what I am trying to accomplish is impossible with the keyboard? Is code my only option?

If anyone knows anything that could help in VBA by all means I will take your advice into consideration.

Unfortunately the webpage is password protected and its a company account therefore I cannot post it.

After right-clicking inspect element in my Chrome browser this is what I see:

<img alt="View Quantities At Other Locations" src="/WebOrder/Images/CheckQtys.gif" 
 title="View Quantities At Other Locations" class="popup"popupdirection="upperleft" 
 popupwidth="380" popupcontent="#ProductQuantitiesForAccessibleBranches" 
 onbeforepopupcreate="onBeforePopupCreate_GetProductQuantitiesForAccessibleBranches(this)" 
 popupajaxformid="GetProductQuantitiesForAccessibleBranches" 
 onbeforepopupajaxpost="onBeforePopupAjaxPost_GetProductQuantitiesForAccessibleBranches(this)" 
 oncompletepopupajaxpost="onCompletePopupAjaxPost_GetProductQuantitiesForAccessibleBranches(this)" 
 productguid="00000000-0000-0000-0000-000000058927" displayitem="732899500" 
 brandguid="00000000-0000-0000-0000-000000000000" brandname="" brandsku=""> 

Does anyone have any ideas how I can set focus to this element (either with my keyboard or VBA)?

Techie
  • 181
  • 4
  • 14
  • Try something like `ie.document.getElementsByTagName("img")(0).focus`, where 0 is the Index of the Img tag on the website. – Ryan Wildry Aug 23 '16 at 17:23
  • hmm, interesting. I tried `.getElementsByClassName` before I posted this question. Now I also tried your method but it doesn't work either. Thanks for trying. – TheGuyOverThere Aug 23 '16 at 17:30
  • @RyanWildry Do you think I need to fire some javascript event before the click? The problem is that all the attributes are `Null` in my locals window so I don't know which one to even try... – TheGuyOverThere Aug 23 '16 at 17:36
  • Can you post the website's URL? Keep in mind, you might need to change the index from 0 as it may not be the first item in the collection. – Ryan Wildry Aug 23 '16 at 17:40
  • Unfortunately I can't. The item number is not a problem. I ran a for loop through all the item numbers so I'm 100% sure. – TheGuyOverThere Aug 23 '16 at 17:52
  • Did you check all frames/iframes as well? This image should be in the collection with all other img tags. – Ryan Wildry Aug 23 '16 at 17:56
  • You know I think you're onto something Ryan! I checked the page from top to bottom and all the frames are at the bottom. I've identified the one I want to interact with. `
    ` I will try the `Forms.Submit` method, using the `ProductGuid` value from the image tag prior to submit.
    – TheGuyOverThere Aug 23 '16 at 18:08
  • Well @RyanWildry sadly no luck. I tired changing the value of the input element inside the form and then submitting it but it still does nothing. I also tried clicking on the image element again after I changed the form value, but this still does the same thing. My code runs fine, but nothing happens on the page. – TheGuyOverThere Aug 23 '16 at 19:00
  • The form or the frame? I was talking about the frame. The element might be in a different frame, which would explain why it wasn't enumerated by `getElementsByTagName`. You may need to iterate over each frame, looking for the `img` tag in question. – Ryan Wildry Aug 23 '16 at 21:48
  • There are no frame tags on the page. There are even comments in the HTML code: "//This page should never load inside of a frame/frameset ..." But you did set me on the right course. I'm still not quite there. Maybe you can help [New Question]http://stackoverflow.com/questions/39111278/form-submit-does-not-go-through-when-using-vba Lol – TheGuyOverThere Aug 23 '16 at 22:01
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/121672/discussion-between-theguyoverthere-and-ryan-wildry). – TheGuyOverThere Aug 23 '16 at 22:03

1 Answers1

0

You can focus on a div using <div tabindex=0> Stuff Here </div>. Place the image inside the div and use the div to manipulate it.

Ale
  • 437
  • 4
  • 17
  • I wish I could. I actually saw something similar on here before I typed my question. The company has an account on the website, but does not own the website. Therefore I cannot change any HTML code. Thanks anyways though! – TheGuyOverThere Aug 23 '16 at 17:16