How to figure out the proper variable type of fx a selenium webdriver method?

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class SecondTestCase {
public static void main(String[] args) {

//Create driver
WebDriver driver = new ChromeDriver();

//Go to website
driver.get("https://demo.opencart.com/");

//Select websearch box
WebElement searchBox = driver.findElement(By.name("search"));
//I know this is WebElement type

driver.findElement(By.name("search"));
//But how would I figure that out from this only?
}
}
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class SecondTestCase {
public static void main(String[] args) {

//Create driver
WebDriver driver = new ChromeDriver();

//Go to website
driver.get("https://demo.opencart.com/");

//Select websearch box
WebElement searchBox = driver.findElement(By.name("search"));
//I know this is WebElement type

driver.findElement(By.name("search"));
//But how would I figure that out from this only?
}
}
I am learning about selenium right now, and was wondering how we know what variable type we should give when we use new methods we never used before. For example driver.findElement(By.name("search")); - how do I figure out what type the variable should be? I know its WebElement but only because I am watching a tutorial. This is just one example, and could be any other Java method or library. In the two pictures, you can see that the instructor (white picture) hovers over the driver. part and he can see that it is type WebElement. When I do the same, it just says its WebDriver driver = new ChromeDriver();.... He uses Eclipse, while I use IntelliJ.
No description
No description
2 Replies
JavaBot
JavaBot8mo ago
This post has been reserved for your question.
Hey @Steadhaven! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
JavaBot
JavaBot8mo ago
Post Closed
This post has been closed by <@305362010374406144>.

Did you find this page helpful?