Hi, I’m trying to write a series of tests to validate data (text, images, and urls). Is there a way to quick capture all objects on the page instead of going through spy web?
Same question here. Is there a way to capture all objects on a page or do they have to be done one at a time?
It is possible in WebDriver.
System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe")WebDriver driver = new ChromeDriver()DriverFactory.changeWebDriver(driver)driver.get("https://www.yourpage.com")List<WebElement> elems = driver.findElements(By.xpath('//*'))
This creates a list of all WebElements on the page. You can even filter by tag name (if you want to verify only some elements).
List<WebElement> filteredElements = new ArrayList<>()List<String> allowedTags = ["a", "div", "img"]for (WebElement elem in elems) { if(allowedTags.contains(elem.getTagName())) { filteredElements.add(elem) }}