this sample work:
get text of google and show in home page sample asp.net
test for correct work selenium in windows host.
i want to run selenium in windows hosting plesk.
error for me:
Server Error in '/' Application.
Expected browser binary location, but unable to find binary in default
location, no 'moz:firefoxOptions.binary' capability provided, and no
binary flag set on the command line (SessionNotCreated)
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Expected browser
binary location, but unable to find binary in default location, no
'moz:firefoxOptions.binary' capability provided, and no binary flag
set on the command line (SessionNotCreated)
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: Expected browser binary location, but
unable to find binary in default location, no
'moz:firefoxOptions.binary' capability provided, and no binary flag
set on the command line (SessionNotCreated)]
OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response
errorResponse) +1059
OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String
driverCommandToExecute, Dictionary`2 parameters) +125
OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities
desiredCapabilities) +235
OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor
commandExecutor, ICapabilities desiredCapabilities) +54
OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxOptions options)
+81 WebDriverwithwebapp._Default.Page_Load(Object sender, EventArgs e) +178
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
EventArgs e) +51 System.Web.UI.Control.OnLoad(EventArgs e) +95
System.Web.UI.Control.LoadRecursive() +59
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+678
protected void Page_Load(object sender, EventArgs e)
{
FirefoxOptions options = new FirefoxOptions();
options.BrowserExecutableLocation = ("C:\\Program Files\\Mozilla Firefox\\firefox.exe"); //This is the location where you have installed Firefox on your machine
// WebDriver driver = new FirefoxDriver(options);
using (var FireFoxPage = new FirefoxDriver())
{
//_driver = new FireFoxDriver();
_driver.Manage().Window.Maximize();
_driver.SwitchTo().Window(_driver.CurrentWindowHandle);
_driver.Manage().Cookies.DeleteAllCookies();
// _driver.Manage().Timeouts().ImplicitWait(TimeSpan.FromSeconds(3));
_driver.Navigate().GoToUrl("https://google.com/");
_driver.FindElement(By.Id(Button_ID)).Click();
IwebElement Element1 = _driver.FindElement(By.XPath("/html/body/main/div/div/div[3]/span"));
ksc = Element1.Text.ToString();
Label1.Text = ksc.ToString();
_driver.Quit();
Process[] geckodriverProcesses = Process.GetProcessesByName("geckodriver");
foreach (var geckodriver in geckodriverProcesses)
{
geckodriver.Kill();
}
}
}
Try passing the options variable into the parameters of new FirefoxDriver(). It worked for me like this:
FirefoxOptions options = new FirefoxOptions();
options.BrowserExecutableLocation = ("C:\\Program Files\\Mozilla Firefox\\firefox.exe"); //This is the location where you have installed Firefox on your machine
// WebDriver driver = new FirefoxDriver(options);
using (var FireFoxPage = new FirefoxDriver(options))
{
//...
Actually, I see a commented variable using the options object, did you have any errors using it instead?
Find the installed location of firefox
e.g. C:\Program Files\Mozilla Firefox\firefox.exe
FirefoxOptions option = new FirefoxOptions();
option.BrowserExecutableLocation = "C:\\Program Files\\Mozilla Firefox\\firefox.exe";
//Location of geckodriver.exe file in project solution
string path = "C://Users//v-sacgupta//source//repos//PracticeExcersice//PracticeExcersice//drivers//";
driver = new FirefoxDriver(path + #"/drivers/", option);
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("https://google.com");
Related
I have a Framework 4.8 C# app that uses ClearScript to allow JavaScript to be used as an extension language. I am able to write plugins as DLLs and attach them at runtime, viz
JSE.Script.attach = (Func<string, bool>)Attach;
...
private static bool Attach(string dllPath, string name = "")
{
var status = false;
var htc = new HostTypeCollection();
try
{
var assem = Assembly.Load(AssemblyName.GetAssemblyName(dllPath));
htc.AddAssembly(assem);
if (name.Length == 0)
{
name = assem.FullName.Split(',')[0];
}
JSE.AddHostObject(name, htc); //FIXME checkout the hosttypes
Console.Error.WriteLine($"Attached {dllPath} as {name}");
status = true;
}
catch (ReflectionTypeLoadException rtle)
{
foreach (var item in rtle.LoaderExceptions)
{
Console.Error.WriteLine(item.Message);
T.Fail(item.Message);
}
}
catch (FileNotFoundException fnfe)
{
Console.Error.WriteLine(fnfe.Message);
T.Fail(fnfe.Message);
}
catch (Exception e)
{
Console.Error.WriteLine(e.Message);
T.Fail(e.Message);
}
return status;
}
This permits my scripts to have lines like
attach(".\\Plugin_GoogleAds_Metrics.dll");
H = Plugin_GoogleAds_Metrics.GoogleAds_Metrics.Historical;
H.EnableTrace("GAM");
...
I've made a public repo of the plugin for those interested.
What's not working in this situation is that when I try to execute the plugin's GetAccountInformation method, and execution reaches the GoogleAdsServiceClient googleAdsService = client.GetService(Services.V11.GoogleAdsService); line, an error is thrown complaining about Google.Protobuf, viz
Exception has been thrown by the target of an invocation.
at JScript global code (Script [23] [temp]:5:0) -> acc = H.GetAccountInformation(auths.Item1, 7273576109, true)
at Microsoft.ClearScript.ScriptEngine.ThrowScriptError(IScriptEngineException scriptError)
at Microsoft.ClearScript.Windows.WindowsScriptEngine.ThrowScriptError(Exception exception)
at Microsoft.ClearScript.Windows.WindowsScriptEngine.<>c__DisplayClass57_0`1.<ScriptInvoke>b__0()
at Microsoft.ClearScript.ScriptEngine.ScriptInvokeInternal[T](Func`1 func)
at Microsoft.ClearScript.ScriptEngine.ScriptInvoke[T](Func`1 func)
at Microsoft.ClearScript.Windows.WindowsScriptEngine.ScriptInvoke[T](Func`1 func)
at Microsoft.ClearScript.Windows.WindowsScriptEngine.Execute(UniqueDocumentInfo documentInfo, String code, Boolean evaluate)
at Microsoft.ClearScript.Windows.JScriptEngine.Execute(UniqueDocumentInfo documentInfo, String code, Boolean evaluate)
at Microsoft.ClearScript.ScriptEngine.Evaluate(UniqueDocumentInfo documentInfo, String code, Boolean marshalResult)
at Microsoft.ClearScript.ScriptEngine.Evaluate(DocumentInfo documentInfo, String code)
at Microsoft.ClearScript.ScriptEngine.Evaluate(String documentName, Boolean discard, String code)
at Microsoft.ClearScript.ScriptEngine.Evaluate(String documentName, String code)
at Microsoft.ClearScript.ScriptEngine.Evaluate(String code)
at RulesetRunner.Program.Run(JScriptEngine& jSE, String scriptText, Config cfg, Dictionary`2 settings) in C:\Users\bugma\Source\Repos\Present\BORR\RulesetRunner\RunManagementPartials.cs:line 72
Exception has been thrown by the target of an invocation.
Exception has been thrown by the target of an invocation.
Could not load file or assembly 'Google.Protobuf, Version=3.15.8.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604' or one of its dependencies. The system cannot find the file specified.
So
I am using the latest Google.Ads.GoogleAds library
AutoGenerateBindingRedirects has been set to true in the csproj file
Add-BindingRedirect has been executed in the context of the Plugin's project
The Plugin_GoogleAds_Metrics.dll is in the same folder as the Google.Protobuf.dll
Where to from here?
What fixed this was including Google.Ads.GoogleAds in the calling app. I didn't have to explicitly mention the symbols in the main binary, just have the library in the build. What I expect this did was to include all the relevant DLLs next to the main EXE.
This is definitely not what I wanted. I wanted to be able to hive off all the DLLs into a separate plugin folder and only have them connected when I attached the plugin. Sadly, this does not seem to be achievable at this point. And now I'm wondering about the other plugins I've written that use Google technologies.
I found this code:
using System.DirectoryServices;
...
void Recycle(string appPool)
{
string appPoolPath = "IIS://servername/W3SVC/AppPools/" + appPool;
using (DirectoryEntry appPoolEntry = new DirectoryEntry(appPoolPath))
{
appPoolEntry.Invoke("Recycle", null);
appPoolEntry.Close();
}
}
But when I try to use this code I have this error:
Exception has been thrown by the target of an invocation., StackTrace: at System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args)
What I'm doing wrong?
or how can get info about status of my application pool, and how can I start and stop my app pool without any special permissions?
I'am using built-in account: NetworkService
Try to use Microsoft.Web.Administration.ServerManager and Microsoft.Web.Administration.ApplicationPool classes.
Example:
var serverManager = new ServerManager();
var appPool = serverManager.ApplicationPools.FirstOrDefault(ap => ap.Name.Equals("AppPoolName"));
appPool.Start();
namespace Selenium_test
{
class Program
{
static void Main(string[] args)
{
string Path = #"C:\Users\Anjali10\.nuget\packages\WebDriverChromeDriver\2.10.0\tools";
//Create the reference of our browser
IWebDriver driver = new ChromeDriver(Path);
// Thread.Sleep(TimeSpan.FromSeconds(3000));
Thread.Sleep(300000);
//Navigate to google page
driver.Navigate().GoToUrl("https://www.google.com");
//Find the element
IWebElement element = driver.FindElement(By.Name("q"));
//Perform Operation
element.SendKeys("Dynamics Lifecycle Services");
driver.Close();
}
}
}
this code opens chrome for split second and then throws exception as below
An unhandled exception of type 'System.InvalidOperationException'
occurred in WebDriver.dll
Additional information: unknown error: unrecognized Blink revision:
49721773c8dd62828e471ca69e2c89767f98c690
A cmd promt opens with message :
Only local connections are allowed.
Please help to resolve. thanks in advance
I want to unzip a file with ZipFile class in c# (VS2012).
Even if I copy the paths directly from win explorer I get this error:
System.ArgumentException: Illegales Zeichen im Pfad. bei
System.IO.Path.CheckInvalidPathChars(String path, Boolean
checkAdditional) bei System.IO.Path.GetFileName(String path) bei
System.IO.Compression.ZipHelper.EndsWithDirChar(String test) bei
System.IO.Compression.ZipArchiveEntry.set_FullName(String value)
bei System.IO.Compression.ZipArchiveEntry..ctor(ZipArchive archive,
ZipCentralDirectoryFileHeader cd) bei
System.IO.Compression.ZipArchive.ReadCentralDirectory() bei
System.IO.Compression.ZipArchive.get_Entries() bei
System.IO.Compression.ZipFileExtensions.ExtractToDirectory(ZipArchive
source, String destinationDirectoryName) bei
System.IO.Compression.ZipFile.ExtractToDirectory(String
sourceArchiveFileName, String destinationDirectoryName, Encoding
entryNameEncoding) bei
System.IO.Compression.ZipFile.ExtractToDirectory(String
sourceArchiveFileName, String destinationDirectoryName) bei
WindowsFormsApplication1.MainForm.buttonStartNxtOSEK_Click(Object
sender, EventArgs e) in
d:\C#\nxtOSEKInstaller\nxtOSEKSetup\WindowsFormsApplication1\Form1.cs:Zeile
192.
Code:
string zipPath = #"D:\C#\nxtOSEKInstaller\nxtOSEKSetup\WindowsFormsApplication1\bin\Debug\res\package.zip";
string extractPath = #"D:\testcyginstall\cygwin";
textBoxProgress.AppendText("Entpacke .... ");
try {
ZipFile.ExtractToDirectory(zipPath, extractPath);
} catch (System.ArgumentException ex) {
textBoxProgress.AppendText("\n" + "Error\n" + ex.ToString());
return;
}
EDIT
Problem solved: Some files with chinese file names in the zip file caused the problem.
It's very frustrating when the exception does not output the problematic path name.
As you already know some characters are not valid on windows:
\ / : * ? " < > |
This would bring a lot of situations when your application receives zip from different OS since some of those invalid characters are valid in other OS.
In order to solve this problem you can sanitize your files names before you extract them:
public void ExtractZipFileToPath(
string zipFilePath,
string ouputPath
)
{
using (var zip = ZipFile.Read(zipFilePath))
{
foreach (var entry in zip.Entries.ToList())
{
entry.FileName = SanitizeFileName(entry.FileName);
entry.Extract(ouputPath);
}
}
}
Sanitizing examples here How to remove illegal characters from path and filenames?
Trying to access google spreadsheets using their api. following their example, the code doesnt work, and its not obvious why. All I'm trying to do is to connect, and I keep getting back the same error. This is with their code set as of 4/15/10. Can anyone offer any suggestion on what I'm doing wrong?
CodE:
using System;
using Google.GData.Client;
using Google.GData.Extensions;
using Google.GData.Spreadsheets;
namespace google_spreadsheet
{
class Program
{
static void Main(string[] args)
{
SpreadsheetsService myService = new SpreadsheetsService("MySpreadsheet" );
myService.setUserCredentials("account#gmail.com", "xxxxxxx");
string token1 = myService.QueryClientLoginToken();
Console.WriteLine("token is {0}", token1);
Console.ReadLine();
SpreadsheetQuery query = new SpreadsheetQuery();
SpreadsheetFeed feed = myService.Query(query);
Console.WriteLine("list");
foreach (SpreadsheetEntry entry in feed.Entries)
{
Console.WriteLine("Value: {0}", entry.Title.Text);
When I run this, it keeps erroring out at the myService.Query statement, with the following error:
Google.GData.Client.GDataRequestException was unhandled
Message=Execution of request failed: http://spreadsheets.google.com/feeds/spreadsheets/private/full
Source=Google.GData.Client
ResponseString=<HTML>
<HEAD>
<TITLE>Not Found</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Not Found</H1>
<H2>Error 404</H2>
</BODY>
</HTML>
StackTrace:
at Google.GData.Client.GDataRequest.Execute()
at Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter)
at Google.GData.Client.GDataGAuthRequest.Execute()
at Google.GData.Client.Service.Query(Uri queryUri, DateTime ifModifiedSince, String etag, Int64& contentLength)
at Google.GData.Client.Service.Query(Uri queryUri, DateTime ifModifiedSince)
at Google.GData.Client.Service.Query(FeedQuery feedQuery)
at Google.GData.Spreadsheets.SpreadsheetsService.Query(SpreadsheetQuery feedQuery)
at google_spreadsheet.Program.Main(String[] args) in C:\Development Items\VS Projects\VS2008\google_spreadsheet\google_spreadsheet\Program.cs:line 21
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Net.WebException
Message=The remote server returned an error: (404) Not Found.
Source=System
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at Google.GData.Client.GDataRequest.Execute()
InnerException:
Yet, I can take the url
http://spreadsheets.google.com/feeds/spreadsheets/private/full
and manually type it in with my username/password, and it works fine. Any suggestions?
thanks
rocky sanders
I had a similar problem with Mono. In my case it was a problem with certificates, used by SSL.
i believe it's becus u din't specify Uri in document query object
try this instead
DocumentsService service = new DocumentsService("appName");
service.Credentials = new GDataCredentials("email#gmail.com", "password");
DocumentQuery query = new DocumentQuery("http://docs.google.com/feeds/default/private/full/-/contents");
query.Categories.Add(DocumentsListQuery.SPREADSHEETS);
var spreadsheets = service.Query(query).Entries.Cast<DocumentEntry>();