Home > Software engineering >  Is webElement being called by passing the variable of WebElement into constructor of another "A
Is webElement being called by passing the variable of WebElement into constructor of another "A

Time:03-08

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.

CodePudding user response:

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

  • Related