Home > Mobile >  Selenium-Webdriver Explicit Wait Apache JMeter 5.5
Selenium-Webdriver Explicit Wait Apache JMeter 5.5

Time:01-14

I am using Selenium Webdriver in Apache Jmeter 5.5 and require to use explicit wait.The Script Language is Java. Here, is my Sample Code :

import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.*;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

var driver=WDS.browser;

// Load Url
driver.get("https://samplewebsite.com");
driver.manage().window().setSize(new Dimension(1936, 1048));
driver.manage().window().maximize();
driver.findElement(By.xpath(".//span[@class='content']")).click();

// Login 
WebElement username = new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath(".//input[@type='email']")));
driver.findElement(By.xpath(".//input[@type='email']")).click();
driver.findElement(By.xpath(".//input[@type='email']")).sendKeys("sampleUsername");
driver.findElement(By.xpath(".//input[@type='submit']")).click();
driver.findElement(By.xpath(".//input[@type='password']")).click();
driver.findElement(By.xpath(".//input[@type='password']")).sendKeys("samplePassword");
driver.findElement(By.xpath(".//input[@type='submit']")).click();
driver.findElement(By.cssSelector("span")).click();
// login details
WDS.sampleResult.sampleEnd();

In the above code I was facing the below no such element exception:

Target exception: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":".//input[@type='email']"}

Blockquote

So, I used explicit wait as recommended, But, I am facing the following error:

 Sourced file: inline evaluation of: ``import org.openqa.selenium.*; import org.openqa.selenium.support.ui.*; import or . . . '' : Typed variable declaration : Attempt to resolve method: ofSeconds() on undefined variable or class name: Duration : at Line: 15 : in file: inline evaluation of: ``import org.openqa.selenium.*; import org.openqa.selenium.support.ui.*; import or . . . '' : Duration .ofSeconds ( 10 ) 
 in inline evaluation of: ``import org.openqa.selenium.*; import org.openqa.selenium.support.ui.*; import or . . . '' at line number 15

All the xpaths are verified and correct, I am unable find a resolution to above error. I am facing this source file evaluation error for any troubleshooting I am doing.

My objective is to an correct explicit wait before we enter the username & password details in email & password fields respectively.

// Login 
WebElement username = new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath(".//input[@type='email']")));
driver.findElement(By.xpath(".//input[@type='email']")).click();
driver.findElement(By.xpath(".//input[@type='email']")).sendKeys("sampleUsername");
driver.findElement(By.xpath(".//input[@type='submit']")).click();
driver.findElement(By.xpath(".//input[@type='password']")).click();
driver.findElement(By.xpath(".//input[@type='password']")).sendKeys("samplePassword");
driver.findElement(By.xpath(".//input[@type='submit']")).click();
driver.findElement(By.cssSelector("span")).click();

CodePudding user response:

You need to (at least) import the Duration class:

import java.time.Duration

Also don't be confused with java because if you think it's "java" - it is not, you're actually using Beanshell interpreter which is not 100% Java-compatible.

If you want to use something closer to Java - consider switching to groovy language, moreover it's the recommended scripting option since JMeter 3.1

  • Related