October 2018
Intermediate to advanced
192 pages
5h 12m
English
One very useful method in finding XPath is the text() method. When we need to supply some text at runtime, say for example, from an Excel file, then we can utilize the text() method in the following manner:
public class DynamicText { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\\SeleniumWD\\src\\main\\resources\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.get("http://www.google.com"); String variableData = "Google"; String dynamicXpath = "//*[text()='" + variableData + "']"; List<WebElement> elem = driver.findElements(By.xpath(dynamicXpath)); System.out.println("no of elements: ...Read now
Unlock full access