Selenium webdriver JMETER WebDriver-显式等待示例代码

Selenium webdriver JMETER WebDriver-显式等待示例代码,selenium-webdriver,jmeter,Selenium Webdriver,Jmeter,我找到了JMeterWebDriver的显式等待示例代码,但不确定如何使其工作。你能为WebElement提供更多的示例代码吗?是否有任何java库需要导入?下面是我目前为JMeterWebDriver编写的代码。非常感谢 我的代码: import org.openqa.selenium.* import org.openqa.selenium.support.ui.* WDS.sampleResult.sampleStart() WDS.browser.get(“https://uat-tes

我找到了JMeterWebDriver的显式等待示例代码,但不确定如何使其工作。你能为WebElement提供更多的示例代码吗?是否有任何java库需要导入?下面是我目前为JMeterWebDriver编写的代码。非常感谢

我的代码:
import org.openqa.selenium.*
import org.openqa.selenium.support.ui.*
WDS.sampleResult.sampleStart()
WDS.browser.get(“https://uat-testing.com/");
sleep(10000)
WDS.browser.findelelement(org.openqa.selenium.By.xpath(“//input[@type='text']”)xxxx@testing.com");
WDS.browser.findelelement(org.openqa.selenium.By.xpath(“//input[@type='password'])).clear()
WDS.browser.findelelement(org.openqa.selenium.By.xpath(“//input[@type='password']”)xxx@xxxx");
WDS.browser.findelelement(org.openqa.selenium.By.xpath(“//按钮/span”)。单击()
sleep(20000)
WDS.browser.findelelement(org.openqa.selenium.By.xpath(“//div[10]/li/span”)。单击()
WDS.browser.findelelement(org.openqa.selenium.By.xpath(“//div[16]/li/span”)。单击()
WDS.browser.findelelement(org.openqa.selenium.By.xpath(“//div[3]/li/span”)。单击()
WDS.browser.findelelement(org.openqa.selenium.By.xpath(“//div[5]/div/div/div”))。单击()
WDS.browser.findelelement(org.openqa.selenium.By.xpath(“//ul[contains(@id,'dropdown-menu-'))]/li”)。单击()
WDS.browser.findelelement(org.openqa.selenium.By.xpath((//button[contains(@type,'button')])),单击()
sleep(30000)
WDS.sampleResult.sampleEnd()

WebElement示例代码:
WebDriver=new ChromeDriver()
driver.get(“https://google.com/ncr");
driver.findElement(By.name(“q”)).sendKeys(“cheese”+Keys.ENTER)
//初始化并等待元素(链接)可点击-10秒后超时
WebElement firstResult=newwebdriverwait(驱动程序,持续时间秒(10))
.until(ExpectedConditions.elementToBeClickable(By.xpath(“//a/h3”))
//打印第一个结果
System.out.println(firstResult.getText())

没有提供示例

WebDriver driver = new ChromeDriver();
driver.get("https://google.com/ncr");
driver.findElement(By.name("q")).sendKeys("cheese" + Keys.ENTER);
// Initialize and wait till element(link) became clickable - timeout in 10 seconds
WebElement firstResult = new WebDriverWait(driver, Duration.ofSeconds(10))
        .until(ExpectedConditions.elementToBeClickable(By.xpath("//a/h3")));
// Print the first result
System.out.println(firstResult.getText());
您只需删除第一行,然后用
WDS.browser
替换
driver

中的最小示例代码为:

WDS.sampleResult.sampleStart()
WDS.browser.get('http://example.com')
def wait = new org.openqa.selenium.support.ui.WebDriverWait(WDS.browser, 5)
wait.until(org.openqa.selenium.support.ui.ExpectedConditions.elementToBeClickable(org.openqa.selenium.By.xpath("//a[contains(text(),'More information')]")))
WDS.sampleResult.sampleEnd()

我不愿意修复您的代码,因为您甚至懒得对其进行正确格式化,所以我将把它留给您。

非常感谢Dmitri t。您可以在顶部定义
var driver=WDS.browser
,使代码看起来更简单。例如
driver.get(URL)
而不是
WDS.browser.get(URL)