首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IntelliJ IDEA获取元素文本

IntelliJ IDEA获取元素文本
EN

Stack Overflow用户
提问于 2020-01-22 15:22:05
回答 1查看 434关注 0票数 0

在使用Katalon之前,我是IntelliJ IDEA的新手,但现在我使用了IntelliJ IDEA。我无法得到一个元素文本。我尝试了很多东西,但仍然不能得到一个元素的文本。我是用groovy语言写的,这就是我想要做的:

代码语言:javascript
复制
System.setProperty("webdriver.chrome.driver", PATH + "\\chromedriver.exe")
ChromeOptions options = new ChromeOptions()

options.setExperimentalOption("useAutomationExtension", false)

WebDriver driver = new ChromeDriver(options)
def url = "https://www.google.com"
driver.get(url)

List<WebElements> element = driver.findElements(By.xpath("//*[@id="tsf"]/div[2]/div[1]/div[3]/center/input[1]"))

println(element)
println(element.text)

element.text不工作,我也尝试过element.getText(),但是没有找到这个类:这是我导入的类:

代码语言:javascript
复制
import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement as WebElements
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions

P.S:,我也不能使用像element.click(), element.getAttribute(), etc这样的方法

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-23 07:24:43

当我尝试按索引打印元素时,问题得到了解决,因为我的元素是一个列表web元素。

代码语言:javascript
复制
element.get(0).getText()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59862960

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档