I am using Java and Selenium Webdriver in order to test the functionalities of a single page web application.
For this reason, clearly, elements are injected and removed from the DOM dynamically.
I know I can wait for an element to be present in the DOM using similar code that is using WebDriverWait (very neat template I wrote slightly changing GitHub):
public void waitForElement() throws Exception {
/*
Inject the following snippet in any web page to test the method
<button class="i-am-your-class" onclick="alert('Wow, you pressed the button!');">Press me</button>
*/
System.setProperty("webdriver.gecko.driver", "C:\Program Files (x86)\Mozilla Firefox\geckodriver.exe");
WebDriver driver = getDriver();
WebDriverWait wait = new WebDriverWait(driver, 10); // 10 can be reduced as per Test Specifications
driver.get("http://www.google.com");
WebElement response = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@class='i-am-your-class']")));
response.click();
System.out.println("*****************************************************************************");
System.out.println(response);
System.out.println(response.getText());
driver.close();
}
What I would like to know is if this is also the more efficient way to obtain such result using an xpath.
I have been researching on Stackoverflow and several answers point in a similar direction but no answer is focused on efficiency / performances:
Thanks for your time and help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…