C# press key multiple times

Asked

Viewed 91 times

-1

I’m using c# to navigate enttet buttons and textbox a page. For this I use the TAB key because the names of the page objects are dynamic, every time the site updates the id and class change.

I’m using the following syntax:

pg.findElement(By.Name("nome_ficticio")).sendKeys(keys.Tab + keys.Tab + keys.Tab....)

There’s a way I could have Tab pressed repeatedly more efficiently?

  • Present more of your code and the structure of the page you are trying to interact with... maybe it is the case of changing your selector instead of being "given" tab...

  • Have you tried to save content in a session ?

1 answer

1


There’s a way I could have Tab pressed repeatedly more efficiently?

Yes, you can do this by creating a Extension Method and a bow for.

Ex:

static class IWebElementExtensions
{
    public static void SendKeysRepeat(this IWebElement element, string text, int qty)
    {
        for (int i = 0; i < qty; i++)
            element.SendKeys(text);
    }
}

Use:

pg.findElement(By.Name("nome_ficticio")).SendKeysRepeat(keys.Tab, 3);

NOTE: Apparently you are not using C# but Java. If it is, you can try to take a look at how Extension Method is done in Java through the link: https://stackoverflow.com/questions/4359979/java-equivalent-to-c-sharp-extension-methods

Browser other questions tagged

You are not signed in. Login or sign up in order to post.