单击带有 soapui 和 selenium 的按钮
Click in button with soapui and selenium
我正在尝试使用 soapui 和 selenium 单击带有以下句子的按钮:
import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.support.ui.ExpectedConditions
import org.openqa.selenium.support.ui.WebDriverWait
import org.openqa.selenium.remote.DesiredCapabilities
import org.openqa.selenium.Keys
import org.openqa.selenium.support.ui.Select
import org.openqa.selenium.JavascriptExecutor
import org.openqa.selenium.WebDriver.Window
import org.openqa.selenium.WebDriver.Options
import org.openqa.selenium.WebDriverException
import java.util.Date;
import org.apache.commons.lang.StringUtils;
import java.util.regex.Pattern
import java.util.regex.Matcher
// Create a new instance of the Chrome driver //Set up the driver def
chromeExecLoc = context.expand( '${#Project#chromeExecLoc}' )
System.setProperty("webdriver.chrome.driver",chromeExecLoc)
//Define driver WebDriver driver = new ChromeDriver()
WebDriverWait wait = new WebDriverWait(driver,20);
def defaultURL = context.expand( '${#Project#urllogin}' ) //def
logoffURL = context.expand( '${#TestSuite#logoffURL}' )
// *******************************************************login*******************************************************
log.info("****** Login ******")
//url driver.get(defaultURL) driver.manage().window().maximize()
driver.manage().deleteAllCookies();
//load , waiting for login button def loginId = context.expand('${#TestSuite#loginId}' )
wait.until(ExpectedConditions.elementToBeClickable(By.class(ymwc-trigger)))
属性:
<li id="menu-item-31998" class="mymwc-trigger menu-item menu-item-type-custom
menu-item-object-custom menu-item-31998">
我想点击,然后显示登录和通过表单,但我在以下代码行遇到错误:
wait.until(ExpectedConditions.elementToBeClickable(By.class(ymwc-trigger)))
你能帮帮我吗?
谢谢
您可以使用以下代码行来代替 By.class(ymwc-trigger)
:
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//li[@class='mymwc-trigger menu-item menu-item-type-custom menu-item-object-custom' and starts-with(@class,'menu-item-') and starts-with(@id,'menu-item-')]")))
更新
根据您看到以下错误的评论:
org.openqa.selenium.TimeoutException: Timed out after 20 seconds waiting for element to be clickable: By.xpath: //li[@class='mymwc-trigger menu-item menu-item-type-custom menu-item-object-custom' and starts-with(@class,'menu-item-') and starts-with(@id,'menu-item-')] Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:17:32' System info: host: 'ProBook-450-G3', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-103-generic', java.version: '1.8.0_144' Driver info: driver.version: unknown error at line: 49
原因
原因是您的 Selenium
版本:'2.41.0' 太旧了。 Driver info
:driver.version:未知。
解决方案
更新 Selenium Client
至 3.8.1 级别和 WebDriver
最新版本的变体。执行你的 Test
.
我正在尝试使用 soapui 和 selenium 单击带有以下句子的按钮:
import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.support.ui.ExpectedConditions
import org.openqa.selenium.support.ui.WebDriverWait
import org.openqa.selenium.remote.DesiredCapabilities
import org.openqa.selenium.Keys
import org.openqa.selenium.support.ui.Select
import org.openqa.selenium.JavascriptExecutor
import org.openqa.selenium.WebDriver.Window
import org.openqa.selenium.WebDriver.Options
import org.openqa.selenium.WebDriverException
import java.util.Date;
import org.apache.commons.lang.StringUtils;
import java.util.regex.Pattern
import java.util.regex.Matcher
// Create a new instance of the Chrome driver //Set up the driver def
chromeExecLoc = context.expand( '${#Project#chromeExecLoc}' )
System.setProperty("webdriver.chrome.driver",chromeExecLoc)
//Define driver WebDriver driver = new ChromeDriver()
WebDriverWait wait = new WebDriverWait(driver,20);
def defaultURL = context.expand( '${#Project#urllogin}' ) //def
logoffURL = context.expand( '${#TestSuite#logoffURL}' )
// *******************************************************login*******************************************************
log.info("****** Login ******")
//url driver.get(defaultURL) driver.manage().window().maximize()
driver.manage().deleteAllCookies();
//load , waiting for login button def loginId = context.expand('${#TestSuite#loginId}' )
wait.until(ExpectedConditions.elementToBeClickable(By.class(ymwc-trigger)))
属性:
<li id="menu-item-31998" class="mymwc-trigger menu-item menu-item-type-custom
menu-item-object-custom menu-item-31998">
我想点击,然后显示登录和通过表单,但我在以下代码行遇到错误:
wait.until(ExpectedConditions.elementToBeClickable(By.class(ymwc-trigger)))
你能帮帮我吗? 谢谢
您可以使用以下代码行来代替 By.class(ymwc-trigger)
:
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//li[@class='mymwc-trigger menu-item menu-item-type-custom menu-item-object-custom' and starts-with(@class,'menu-item-') and starts-with(@id,'menu-item-')]")))
更新
根据您看到以下错误的评论:
org.openqa.selenium.TimeoutException: Timed out after 20 seconds waiting for element to be clickable: By.xpath: //li[@class='mymwc-trigger menu-item menu-item-type-custom menu-item-object-custom' and starts-with(@class,'menu-item-') and starts-with(@id,'menu-item-')] Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:17:32' System info: host: 'ProBook-450-G3', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-103-generic', java.version: '1.8.0_144' Driver info: driver.version: unknown error at line: 49
原因
原因是您的 Selenium
版本:'2.41.0' 太旧了。 Driver info
:driver.version:未知。
解决方案
更新 Selenium Client
至 3.8.1 级别和 WebDriver
最新版本的变体。执行你的 Test
.