This code works, using Java and Edge browser: System.setProperty("webdriver.edge.driver", "msedgedriver.exe"); WebDriver driver = new EdgeDriver(); driver.get("https://the-internet.herokuapp.com/challenging_dom#edit"); String answer = new String(); ArrayList<WebElement>scripts = new ArrayList<WebElement>((ArrayList<WebElement>) driver.findElements(By.tagName("script"))); for(int i = 0; i < scripts.size(); i++) { String focusText = scripts.get(i).getAttribute("innerHTML"); if(focusText.contains("canvas.strokeText")) { answer = focusText.substring(focusText.indexOf("Answer"), focusText.indexOf("',")); break; } } System.out.println(answer);