Wise Owl Answers - How do I hold Shift and click a link in Selenium for VBA

Wise Owl Answers - How do I hold Shift and click a link in Selenium for VBA This question appeared on a video about working with multiple tabs in selenium what nick wanted to know was how to click on a link while holding down the shift key.

So that the link opens up in a brand new window to demonstrate how this works i'm going to assume that you already know at least the basics of working with selenium in.

Vba and if not we've got a whole bunch of videos in this playlist which explain how it does work for demonstration i'm going to be.

Working with the wikipedia main page and clicking on this link and i've already written the basic code i need to get a reference to that a element so i've got a blank excel.

Workbook saved as a macro enabled file and i've written some basic code in here to launch a new instance of google chrome navigate to the wikipedia main page and.

Get a reference to that specific element clicking on something is one of the most straightforward things i think you can do in selenium.

Wise Owl Answers - How do I hold Shift and click a link in Selenium for VBA

I've got a reference to the element i want to click on stored in this variable here called e so to click on that i can simply say e dot click.

If i then run the subroutine i'll find that it loads the wikipedia main page clicks on the wikipedia link and i land on the page i'm interested in but of course this time i want to hold.

Down the shift key while i'm doing that so in the next example we're going to make use of the extra optional parameter of the click method called modifier keys and in order to do.

That most effectively we're going to create a new instance of the selenium keys class to create a new instance of the keys.

Class let's start by declaring a variable so i'm going to call mine ks as selenium.keys we then need to create a new instance of.

That class which we can do in a couple of different ways we could create an auto instancing variable by including the new keyword in the variable declaration.

    Alternatively we could have a separate

    Set statement like we have for our chrome driver class so we can say set ks equals new.

    Selenium dot keys once we've done that we can reference that variable in the modifier keys parameter of the click method so we're going to say ks dot and then.

    All the keys all the special keys have nice sensible names so if i want to reference the shift key i can simply say ks.shift and with that simple difference if we.

    Run the subroutine again this time when we click on our link we don't create or we don't follow the link in the same instance of chrome we follow the link in.

    A completely separate window chrome allows you to hold down a number of different keys when you click on a link to affect the way the link is followed.

    So this time let's hold down the control key instead of the shift key we can say ks dot control then when we run the subroutine again we'll find that the link gets clicked.

    But we open up a new tab in the same instance of chrome we remain on the original main page we don't navigate to that tab if that's something you're interested in.

    Learning how to do then the original question was asked on a video which explains exactly how to work with multiple tabs in selenium.

    You could also hold the ctrl key and the shift key at the same time by concatenating those two keys together in the same argument so we can say ks dot control.

    And then concatenate that with ks dot

    Shift having done that we can run the subroutine again and when we run it we'll see that we open a.

    New tab in the same instance of chrome but this time we navigate to the new tab rather than remaining on the original main page now it doesn't matter which way around.

    You list those keys we could have said shift first and then control and the same thing would have happened so if we change that to shift and control.

    And then run the subroutine again we'll see we get the new tab and navigate to that new tab as well one other interesting thing we can do in chrome is hold down the alt.

    Key while we click on the link to download the link's target so let's change our e dot click ks.control etc let's change that to ks.alt.

    And then i'm just going to show my downloads folder at the moment if i open up the windows explorer window and have a look in the downloads folder there's nothing in there.

    But if i head back to the visual basic editor and then run that subroutine again we'll see that we've triggered the download bar at the bottom.

    And when that's finished if we head back to the downloads folder we can see we've downloaded the html document that was the target of that link.

    So there we go there's the basics of holding down keys while you click on links in google chrome hopefully that's enough to answer nick's original question but if not feel free.

    DISCLAIMER: In this description contains affiliate links, which means that if you click on one of the product links, I'll receive a small commission. This helps support the channel and allows us to continue to make videos like this. All Content Responsibility lies with the Channel Producer. For Download, see The Author's channel. The content of this Post was transcribed from the Channel: https://www.youtube.com/watch?v=OF_R7laJRoM
Postagem Anterior Próxima Postagem