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