Home How do I write a java method to accept click?
Reply: 1

How do I write a java method to accept click?

Knight
1#
Knight Published in 2017-12-06 06:37:09Z

I am creating methods for Selenium testing. How do I write methods that I can use click?

Example

Class.Method(somethingVariable).click()

I know how to make class and method but how do I make .click()

public class MyClass{

    public static void newMethod(String strName) {
        --------
    }
}

I want to do MyClass.newMethod("something")**.click()**or MyClass.newMethod("something")**.attr("html")**etc

Rafał Laskowski
2#
Rafał Laskowski Reply to 2017-12-06 09:25:09Z

It all depends on what are you trying to do. What you can do is called method chaining. The problem is, you are trying to use static method which is not applicable for method chaining.

If you REALLY want to use Class.staticMethod().click(); then you would have to do something like this:

public class MyClass {
    private WebElement element;

    private MyClass(WebElement element) {
        this.element = element;
    }

    public static MyClass newMethod(String str) {
        //do something and THEN pass WebElement you want to click.
        return new MyClass(element);
    }

    public void click() {
        element.click();
    }
}

//usage
public static void main(String[] args) {
    MyClass.newMethod("myString").click();
}

There is probably a lot to explain, so please, ask me in comments because I don't know which parts you do or don't understand.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.301212 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO