0

I'm new in IntelliJ IDEA, before I was using Katalon Studio, but now I use IntelliJ IDEA. I can't get an elements text. I've tried a lot of things, but still can't get an text of an element. I am writing in groovy language, This is what I'm trying to do:

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 does not work, also I've tried element.getText() but that class was not found: This is my imported classes:

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: Also, I'm unable to use methods like element.click(), element.getAttribute(), etc

nopassport1
  • 1,821
  • 1
  • 25
  • 53
brithwulf
  • 538
  • 10
  • 35
  • Isn't [`getText()`](https://javadoc.io/doc/org.seleniumhq.selenium/selenium-api/2.50.1/org/openqa/selenium/WebElement.html#getText--)? – Alejandro Jan 22 '20 at 19:50
  • element.getText() ? I've tried to use that method. – brithwulf Jan 22 '20 at 20:32
  • First of all, i think relying on an IDE as your "primary build tool" is a very bad descicion, but anyway: please be specific what "does not work" means; add your stacktraces or your error message. – cfrick Jan 23 '20 at 07:01
  • I've figured it out. Well, as element is a list of web elements, I should use indexation. element.get(0).getText() works perfectly. – brithwulf Jan 23 '20 at 07:22
  • I'm not relying IDE as my "primary build tool", I just use groovy language in it instead of java. – brithwulf Jan 23 '20 at 07:23

1 Answers1

0

Problem was solved, when I tried to print element by index, as my element is a list web element.

element.get(0).getText()
brithwulf
  • 538
  • 10
  • 35