1. Background
It is necessary to complete the timing push function of a statistical report, and open the statistical report interface for screenshots at all timings. After searching online, I finally decided to use the selenium component to operate the browser.
2. Code
using ; using ; using System; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; namespace ScreenCutIamge { public partial class Form1 : Form { public Form1() { InitializeComponent(); (); this.(); } public void formLoad() { this.txt_document.Text = "pageContentDIV"; this.txt_path.Text = "D:\\cutimage"; this.txt_scal.Text = "40"; this.txt_url.Text = ""; } private void button1_Click(object sender, EventArgs e) { (); } private void cutImage() { var service = (@".", ""); using (IWebDriver driver = new (service)) { ().GoToUrl(this.txt_url.Text); // = ""is the same //var options = new InternetExplorerOptions(); // string script = "='scale(0.5)'"; // (script); (10000); string script = "('" + this.txt_document.Text + "')[0]. = '" + this.txt_scal.Text + "%'"; (script); ().(); ().(); // = true; // options. // var driver = new RemoteWebDriver(options); ITimeouts timeouts = ().Timeouts(); //Set the maximum timeout for searching elements to 30 seconds = new TimeSpan(0, 0, 30); //Set the maximum timeout of page operation to 30 seconds = new TimeSpan(0, 0, 30); //Set the maximum asynchronous timeout of script to 30 seconds = new TimeSpan(0, 0, 30); var source = ; // this.txt_scal.Text = source; Screenshot screenShotFile = ((ITakesScreenshot)driver).GetScreenshot(); string imageName = "test" + ("yyyyMMddHHmmss") + ".png"; if (!(txt_path.Text)) { (txt_path.Text); } imageName = txt_path.Text + "\\" + imageName; (imageName); } } private void timer1_Tick(object sender, EventArgs e) { cutImage(); } } }
Official website
/
This is the article about C# using selenium to implement browser operation and screenshots. For more related content on C# selenium to operate browser, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!