I used Selenium IDE to automate the project. Now I started learning Webdriver. In IDE, there are few commands like label and Goto labels, where I can create a bunch of code under a label and use gotolable to jump to the label. How the same can be done using webdriver.
-
What language are you using?– Paul MuirCommented Mar 4, 2014 at 16:55
-
I am learning Java, and using it to automate– STECommented Mar 5, 2014 at 8:11
-
Thanks Sathiya. It sounds like you are asking about Java Functions (A section of code that can be called from another portion of code, to summarize). Could you put more details into your question. Maybe an example. I will go ahead and write up an answer for your question and if it fits, great. But if you could please still add more information regarding the question. It helps people out a lot when they are searching for the answer to the question you asked. Thanks!– Paul MuirCommented Mar 5, 2014 at 12:52
2 Answers
Webdriver is an API, not a programming language. Java has statement labels and GoTo's, but if you use them frequently, you are not using the language the way it was intended. Consider using if-statements, loops, and methods instead.
It sounds like you are wanting to use functions. These are snippets of code that will allow you to call the code in multiple different portions of your program. Functions are amazing and extremely important to understand if you want to progress with the WebDriver.
Here is an extremely simple example function:
protected void functionExample(String text) {
System.out.println(text);
}
And this function would be called with functionExample("test");
and it would print the word 'test' to your output. I strongly STRONGLY suggest learning the basics to Java before continuing with the WebDriver. Build some simple Hello World scripts and study some string manipulation techniques.
If you need more information regarding functions, Java has an extensive community and I am confident that you can find a lot of amazing resources for it.