Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

1 like 0 dislike
176 views
in Selenium by The go-to Tester (391 points)
How may I use JavaScript to select an element when using Page Object Model design pattern?

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)

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.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...