1
How may I use JavaScript to select an element when using Page Object Model design pattern?

Open 1 Answers 25 Views Selenium
How may I use JavaScript to select an element when using Page Object Model design pattern?

1 Answer

0

Here is the sample code.

 

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
 
public class SampleLoginPage {
 
WebDriver driver;
By signInMenu = By.xpath("//*[@id='navbar']/div[2]/div/div/div[2]/div[2]/div[2]/div[1]/span[1]");
 
public LoginPage(WebDriver driver)
{
this.driver = driver;
}
 
public void clickSignInMenu()
{
 
WebDriverWait wait = new WebDriverWait(driver, 45);
wait.until(ExpectedConditions.visibilityOfElementLocated(signInMenu)); 
JavascriptExecutor exe = (JavascriptExecutor)driver;
WebElement ele = driver.findElement(signInMenu)l
exe.executeScript("arguments[0].click();", ele );
}
}
 
Hope it helps.
answered Oct 9, 2016 by stbadmin (4,970 points)
...