selenium - 点击带有soapui和 Selenium 的按钮

标签 selenium grails soapui

我正在尝试使用以下句子单击带有 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 : 驱动程序版本:未知 .

解决方案

更新 Selenium Client 3.8.1 水平和 WebDriver 最新版本的变体。执行您的 Test .

关于selenium - 点击带有soapui和 Selenium 的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48398602/

相关文章:

java - 如何从java中的selenium测试类获取url

java - 如何将整个滚动 <div> 捕获到图像中

eclipse - resources.groovy 中的 Grails bean 配置在 Eclipse STS 中失败

c# - 如何使用 SOAP UI 传递 DTO

groovy - 默认情况下,Soap UI 在 new File() Groovy Script 中在哪里查找文件?我如何改变这个?

python - 让 Selenium 与任何浏览器一起工作?

java - 如何在不使用 Maven 的情况下设置 Selenium WebDriver?

java - 在 Grails 中使用 Hibernate Annotated Java 类时的日期问题

grails - 我可以使用UIPerformance grails插件并将静态资源托管在另一个域中吗?

testing - 使用 SOAP ui 创建请求