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
Problem was solved, when I tried to print element by index, as my element is a list web element.
element.get(0).getText()