Java xpath(包含(text(),“Some text”)给出错误消息
下面的代码表示“类型测试的方法text()未定义”,并提示我在类测试中创建一个新函数text()Java xpath(包含(text(),“Some text”)给出错误消息,java,selenium,selenium-webdriver,automation,Java,Selenium,Selenium Webdriver,Automation,下面的代码表示“类型测试的方法text()未定义”,并提示我在类测试中创建一个新函数text() driver.findElement(By.xpath(contains(text(), "menu"))); 我正在使用Eclipse开普勒和Selenium 2.39.0 我收到的例外情况是:org.openqa.selenium.NoSuchElementException。 我不知道我错在哪里。XPath表达式需要用引号括起来-而且由于您试图解析的表达式也包含字符串文本,我建议您将文本切换
driver.findElement(By.xpath(contains(text(), "menu")));
我正在使用Eclipse开普勒和Selenium 2.39.0
我收到的例外情况是:org.openqa.selenium.NoSuchElementException
。
我不知道我错在哪里。
XPath
表达式需要用引号括起来-而且由于您试图解析的表达式也包含字符串文本,我建议您将文本切换为单撇号”
。另外,除非您希望根元素包含文本menu
,则需要更具体地说明要搜索的元素。例如,以下xpath:
driver.findElement(By.xpath("//*[contains(text(), 'menu')]"));
将找到带有文本“menu”的li
元素(注意xpath区分大小写):
编辑(操作将实际的html向上放置)
这将找到DIV
元素:
driver.findElement(By.xpath("//li[contains(text(), 'menu')]"));
driver.findElement(By.xpath("//DIV[@style[contains(., 'menubar_menubutton.png')]]"));
请注意,xpath是区分大小写的-因此您需要复制SHOUTCASE标记。
xpath
表达式需要用引号括起来-并且由于您尝试解析的表达式还包含字符串文本,因此我建议您将文本切换为单撇号”
。此外,除非您希望使用根e元素要包含文本菜单
,您需要更具体地说明正在搜索的元素。例如,以下xpath:
driver.findElement(By.xpath("//*[contains(text(), 'menu')]"));
将找到带有文本“menu”的li
元素(注意xpath区分大小写):
编辑(操作将实际的html向上放置)
这将找到DIV
元素:
driver.findElement(By.xpath("//li[contains(text(), 'menu')]"));
driver.findElement(By.xpath("//DIV[@style[contains(., 'menubar_menubutton.png')]]"));
请注意,xpath是区分大小写的-因此您需要复制SHOUTCASE标记。
xpath
表达式需要用引号括起来-并且由于您尝试解析的表达式还包含字符串文本,因此我建议您将文本切换为单撇号”
。此外,除非您希望使用根e元素要包含文本菜单
,您需要更具体地说明正在搜索的元素。例如,以下xpath:
driver.findElement(By.xpath("//*[contains(text(), 'menu')]"));
将找到带有文本“menu”的li
元素(注意xpath区分大小写):
编辑(操作将实际的html向上放置)
这将找到DIV
元素:
driver.findElement(By.xpath("//li[contains(text(), 'menu')]"));
driver.findElement(By.xpath("//DIV[@style[contains(., 'menubar_menubutton.png')]]"));
请注意,xpath是区分大小写的-因此您需要复制SHOUTCASE标记。
xpath
表达式需要用引号括起来-并且由于您尝试解析的表达式还包含字符串文本,因此我建议您将文本切换为单撇号”
。此外,除非您希望使用根e元素要包含文本菜单
,您需要更具体地说明正在搜索的元素。例如,以下xpath:
driver.findElement(By.xpath("//*[contains(text(), 'menu')]"));
将找到带有文本“menu”的li
元素(注意xpath区分大小写):
编辑(操作将实际的html向上放置)
这将找到DIV
元素:
driver.findElement(By.xpath("//li[contains(text(), 'menu')]"));
driver.findElement(By.xpath("//DIV[@style[contains(., 'menubar_menubutton.png')]]"));
请注意,xpath是区分大小写的,因此您需要复制SHOUTCASE标记。我觉得有一种更简单的方法可以做到这一点 我个人会做:
WebElement we = driver.findElement(By.Id("123"))
或者,如果您想利用css选择器,您可以:
WebElement we = driver.findElement(By.cssSelector("li:nth-child(1)")) //baring you know the index of the list
我觉得有一种更简单的方法可以做到这一点 我个人会做:
WebElement we = driver.findElement(By.Id("123"))
或者,如果您想利用css选择器,您可以:
WebElement we = driver.findElement(By.cssSelector("li:nth-child(1)")) //baring you know the index of the list
我觉得有一种更简单的方法可以做到这一点 我个人会做:
WebElement we = driver.findElement(By.Id("123"))
或者,如果您想利用css选择器,您可以:
WebElement we = driver.findElement(By.cssSelector("li:nth-child(1)")) //baring you know the index of the list
我觉得有一种更简单的方法可以做到这一点 我个人会做:
WebElement we = driver.findElement(By.Id("123"))
或者,如果您想利用css选择器,您可以:
WebElement we = driver.findElement(By.cssSelector("li:nth-child(1)")) //baring you know the index of the list
text()
可能是Hamcrest matchers样式的静态方法,如果要在不指定类的情况下使用它,则需要一个import static
。我是一个新手。我应该将import static子句放在哪里。提供imports的库文档应该有说明。您需要将xpath
括在引号中,即driver.findElement(By.xpath(“contains(text(),'menu')));
我现在遇到了这个错误:xpath表达式“contains(text(),'menu')”无法计算或不会生成WebElement。text()
大概是Hamcrest matchers风格的静态方法,如果您打算在不指定类的情况下使用它,则需要一个导入静态方法。我是一个新手。我应该将import static子句放在哪里。提供导入的库文档
应该有说明。您需要将xpath
括在引号中,即driver.findElement(By.xpath(“contains(text(),'menu')));
我现在遇到了这个错误:xpath表达式“contains(text(),'menu')”无法计算或不会生成WebElement。text()
大概是Hamcrest matchers风格的静态方法,如果您打算在不指定类的情况下使用它,则需要一个导入静态方法。我是一个新手。我应该将import static子句放在哪里。提供导入的库文档
应该有说明。您需要将xpath
括在引号中,即driver.findElement(By.xpath(“contains(text(),'menu')));
我现在遇到了这个错误:xpath表达式“contains(text(),'menu')”无法计算或不会生成WebElement。text()
大概是Hamcrest matchers风格的静态方法,如果您打算在不指定类的情况下使用它,则需要一个import static
。我是新手。我应该将import static子句放在哪里。