I can't seem to figure out what is going on here.
I have posted below my code and a photo:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace test
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
ChromeOptions options = new ChromeOptions();
options.AddExtensions(new File("pathtoextentions.crx"));
IWebDriver driver = new ChromeDriver(options);
//Test Opening Website
driver.Navigate().GoToUrl("https://google.com");
}
}
}
I have also uploaded a photo here where it show my error is on new File: https://ibb.co/Lk72dsD
Error CS0712 Cannot create an instance of the static class 'File'
What am I doing wrong?
File is a static class, you can't create instances of it like new File().
Looking at ChormeOptions.AddExtensions, it accepts an array or an IEnumerable of string.
So, we could use an array in your case. To do so, replace this:
options.AddExtensions(new File("pathtoextentions.crx"));
with this:
options.AddExtensions(new[] { "pathtoextentions.crx" });
Related
I am new to C# and testing Microsoft.DirectX.AudioVideoPlayback library function.(using VS2019)
VS said there are no error, but nothing happened when I compiled it.
I have tested below code line by line. and found that Init() function does not work at all. I have tested other paths such as
#"C:\Users\name\Videos\sample.mp4"
"C:\Users\name\Videos\sample.mp4"
"C:\Users\name\Videos\sample.mp4"
but all of them does not work at all too.
How to fix the code and why it did`t work properly?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.DirectX.AudioVideoPlayback;
using System.IO;
namespace hello
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Init();
}
public void Init()
{
Video v = Video.FromFile(#"C:\Users\name\Videos\sample.mp4");
v.Owner = this;
v.Size = new Size(1920, 1080);
v.Play();
}
}
}
This might be too simple question, but cannot gain any solution from other answers in this site.
I am getting 'Method must have a return type' whenever i tried to run this project. I would appreciate your help as i have been struggling to resolve this issue to no avail. Thank you
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Appium.Enums;
using System.Threading;
namespace AppiumTest
{
public class Class1
{
AppiumDriver driver;
TestMethod1()
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability("MobileCapabilityType.deviceName", "Test");
capabilities.SetCapability("MobileCapabilityType.deviceName", "Test");
capabilities.SetCapability("MobileCapabilityType.platformVersion", "Emulator");
capabilities.SetCapability("MobileCapabilityType.platformName", "Android");
capabilities.SetCapability("MobileCapabilityType.appPackage", "");
capabilities.SetCapability("MobileCapabilityType.appActivity", "");
driver = new AndroidDriver<AppiumWebElement>(new Uri("http://127.0.0.1.4723/wd/hub"), capabilities);
Thread.Sleep(5000);
driver.FindElementById("com.paypoint.energycontrols:id/btn_sign_in").Click();
driver.FindElement(By.Id("com.paypoint.energycontrols:id/et_email")).SendKeys("");
driver.FindElement(By.Id("com.paypoint.energycontrols:id/et_password")).SendKeys("");
driver.FindElementById("com.paypoint.energycontrols:id/btn_show_pass").Click();
driver.FindElementById("com.paypoint.energycontrols:id/btn_sign_in").Click();
}
}
}
Your method declaration has only method name. In C# methods must have return type and a name. Add a void keyword before TestMethod1():
void TestMethod1() { ... }
I' trying to do port forwarding. I've done following:
NATUPNPLib.dll was added to references
NATUPNPLib was added to using section of page
Following codes were written
But a null reference exception thrown
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Net.Sockets;
using System.Net;
using NATUPNPLib;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
UPnPNATClass upnpnat = new UPnPNATClass();
IStaticPortMappingCollection mappings = upnpnat.StaticPortMappingCollection;
foreach (IStaticPortMapping map in mappings)
{
Console.WriteLine(map.ExternalIPAddress);
}
Console.ReadKey();
}
}
}
How can I overcome this problem?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using MySql.Data;
using System.Web.Security;
using System.Data;
using System.IO;
using SurelyKnown.Core;
using System.Configuration;
using System.Collections;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Xml;
using System.Windows.Forms;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethod(EnableSession = true)]
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
int newOrgID = Convert.ToInt32(Session["uOrgID"].ToString());
The error is on the last line
CS0120: An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.Session.get'
WHat should I do to get the session value inside the method.
Use HttpContext.Current.Session
int newOrgID=0;
if(HttpContext.Current.Session["uOrgID"]!=null)
{
int.TryParse(HttpContext.Current.Session["uOrgID"].ToString(),out newOrgID);
}
check for null before using it, something like this:
if(Session["uOrgID"] != null)
{
int newOrgID = Convert.ToInt32(Session["uOrgID"].ToString());
}
You should also read this article to really understand how to access Session state from web services (including web and page methods): Using ASP.NET Session State in a Web Service
I am trying to learn how to use CefSharp as a browser in c# (unless anyone can suggest any better alternatives).
Initially I set the configuration to Any CPU (and edited the .csproj and app.config) , but the browser didn't display any content, instead it just shows a white/grey screen.
I then tried changing the configuration to x64 (as my PC is x64), but after doing got the following errors:
The type or namespace name 'Winforms' does not exist in the
namespace 'CefSharp'
The type or namespace name 'ChromiumWebBrowser' could not be found
The "FindUnderPath" task was not given a value for the required parameter
"Path".
The OutputPath property is not set for project 'cef.csproj'. Please check
to make sure that you have specified a valid combination of Configuration
and Platform for this project. Configuration='Debug' Platform='x64'. This
error may also appear if some other project is trying to follow a project-
to-project reference to this project, this project has been unloaded or is
not included in the solution, and the referencing project does not build
using the same or an equivalent Configuration or Platform.
My code is:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp;
using CefSharp.WinForms;
namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
public ChromiumWebBrowser chrome;
public Form1()
{
InitializeComponent();
InitializeChromium();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void InitializeChromium()
{
CefSettings settings = new CefSettings();
Cef.Initialize(settings);
string url = "https://www.google.co.uk/";
chrome = new ChromiumWebBrowser(url);
this.pContent.Controls.Add(chrome);
chrome.Dock = DockStyle.Fill;
}
private void pContent_Paint(object sender, PaintEventArgs e)
{
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Cef.Shutdown();
}
}
}
Any help or suggestions are greatly appreciated.