Extraire des données à l'aide de sélénium et désactiver JavaScript
package DemoAutomation;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class JSdisableChrome {
//Disabling JS in Chrome
@Test()
public void Chrome_javascript_disable() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Lenovo-I7\\Desktop\\Selenium\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.managed_default_content_settings.javascript", 2);
options.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.google.com/imghp");
driver.findElement(By.name("q")).sendKeys("flowers");
driver.findElement(By.className("Tg7LZd")).click();
Thread.sleep(5000);
driver.quit();
}
}
Said HR