Skip to content
Advertisement

Is webElement being called by passing the variable of WebElement into constructor of another “Actions” class?

System.setProperty("webdriver.chrome.driver","D:\ChromeDriver\chromedriver.exe");  
WebDriver driver = new ChromeDriver();
driver.get("https://www.amazon.com/");
Actions a = new Actions(driver);
WebElement move = driver.findElement(By.cssSelector("a[id='nav-link-accountList']"));
a.moveToElement(move).build.perform();

I didn’t understand the last step.

Advertisement

Answer

The answer is definitely not.

You can see this by debugging the test script you wrote Code example

It will take that element’s ‘By locator’ data (In this case it is By.cssSelector(“a[id=’nav-link-accountList’]”) ) add pass it to the moveToElement() function.

Note: Just imagine if ‘WebElement’ being called every time when it is used somewhere the same logical condition would have been true for the driver as well. That means whenever you would use ‘driver.findElement’ It would go to the first line of code that is ‘WebDriver driver = new ChromeDriver();’ and it would open new browser each time you use ‘driver.findElement’ method

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement