Join 500+ Software Testing professionals. Solve problem and get your problem solved. Register Now!

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

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

1 Answer

0
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 by (151 points)

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
...