Welcome to the Question and Answer site for Software Testing Professionals

You can get your queries resolved from Software Testing Professionals.

Ask a Question

Get answers and give answers to questions from other members.

View All Questions

Get votes and earn points to build your reputation in community.

View Hot Questions

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

Open 1 Answers 27 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 (192 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.

We have resolved 1.2k+ Software Testing queries!

Software Testing Board Weekly update

We will send you handpicked questions that you would love to answer.

View previous campaigns.

Top Contributors

...