您可以参考以下步骤. 从 I want to run my scripts in Edge browser in headless mode.But I am not able to find any proper solution for it.Can anyone suggest on this 解决方案 Here, I assume that you are trying to automate the MS Edge Chromium browser and you want to run selenium tests on the MS Edge browser in headless mode.You can refer to the steps below.Download the Java/C# binding of Selenium 4.00-alpha05 from here.Download the matching version of Microsoft Edge Driver from this page.Example C# code.using OpenQA.Selenium.Edge;using System.Threading;namespace ecwebdriver{ public class edgewebdriver { static void Main(string[] args) { EdgeOptions edgeOptions = new EdgeOptions(); edgeOptions.UseChromium = true; edgeOptions.BinaryLocation = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"; edgeOptions.AddArgument("headless"); edgeOptions.AddArgument("disable-gpu"); var msedgedriverDir = @"E:\webdriver"; var driver = new EdgeDriver(msedgedriverDir, edgeOptions); driver.Navigate().GoToUrl("<website url>"); Thread.Sleep(3000); driver.Close(); } }}JAVA Example code:package selenium_test;import org.openqa.selenium.WebDriver;import org.openqa.selenium.edge.*;public class new_java_class{ public static void main(String[] args) { System.setProperty("webdriver.edge.driver","D:\\edgedriver_win64_83.0.478.45\\msedgedriver.exe"); EdgeOptions op=new EdgeOptions(); op.addArguments("headless"); WebDriver browser = new EdgeDriver(op); browser.get("https://microsoft.com"); }}Note: Change the paths and modify the values in above code as per your own requirements.You can download the Selenium 4.00-alpha05 on any path. you need to add it in your JAVA project by add External Jars option. 这篇关于如何在Edge无头浏览器上运行Selenium脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-16 22:46