So basically I am trying to automate the web. I'm doing this by using Selenium and PhantomJS driver.
In addition to this I am doing it using a proxy. This is where the problems start.
Without the proxy it's working just fine. Using it doesn't. I'm having big trouble trying to debug this.
This is what I am using now to set the proxy:
PhantomJSDriverService service = PhantomJSDriverService.CreateDefaultService();
service.ProxyType = "http";
service.AddArgument(string.Format("--proxy=", proxyL));
I feel like I have tried every single Google result regarding this and none of the different variants have worked so far. If there is anyone who's got experience with using the PhantomJS diver with a proxy I would love some help.
EDIT:
I am now using this code to set the proxy:
options.AddAdditionalCapability(CapabilityType.Proxy, new Dictionary<string, string>
{
{"proxyType", "none"},
{"httpProxy", proxyL}
});
The console window dows show that I'm using the proxy. But it still isn't.
Related
I'm currently working om my very own trade bot and I want to stream realtime cryptocurrency price from coinex.com using websocket (documentation is here: "https://github.com/coinexcom/coinex_exchange_api/wiki").
I start with a windows form project in Visual Studio and add websocketsharp Nuget package to make a connection using this two lines of code:
WebSocket ws = new WebSocket("wss://socket.coinex.com/");
ws.Connect();
but connection is not stablished and I can't continue working on other parts of my program.
after a week searching and googling I have no success. I appreciate any help to solve this problem.
I find the problem. The Coinex.com domain restricted (Blocked) here (In IRAN) and I should use Proxy to bypass restriction. But here there is another problem: How can I set Proxy for websocketsharp? there is a "Setproxy" function in "websocketsharp" but do not work.
I am trying for the very first time to use Selenium. I would like to have a console application that opens a browser, goes to a website, and performs some actions.
To do this I looked up some tutorials. The first one I found is here:
https://learn.microsoft.com/en-us/microsoft-edge/webdriver-chromium/?tabs=c-sharp
I would like to automate Edge.
The first thing I did was get my Edge version, which incidentally decided to update when I went to the about page, something that will no doubt be a problem going forward.
I downloaded the file that corresponded to my version, although for some reason that version is x86 only while all the others are x64...
I then went to NuGet and searched for Selenium.WebDriver. Probably because I'm targeting 4.7.2 the latest version is 3.141 not version 4, but whatever. I install version 3.
I also add a nuget reference to Microsoft.Edge.SeleniumTools as instructed in the guide.
the guide then says use this code:
var options = new EdgeOptions();
options.UseChromium = true;
var driver = new EdgeDriver(options);
However I don't have a UseChromium property, so this does not work.
I removed it, and used the default constructor, however this also doesn't work because it can't find the driver.
So next I passed in the path to the folder the driver is in as a parameter.
This also did not work because it is looking for a file with a different name to the one in the edge driver zip download. It looks for microsoftwebdriver.exe while the zip file contains msedgedriver.exe. Perhaps this is the reason for the error? It actually has a link in the exception when it can't find it of where to download it, however the link is dead.
I renamed the file, and ran the code. A console window appeared with debug information, and the browser opened. Success!
Next I tried to go to a website, with this code:
driver.Url = "https://www.google.com";
However with this I got these errors in the console window:
Starting MSEdgeDriver 94.0.992.38
(55a0a486d5c4c1a7374dc28a7be702fee43b3b39) on port 1307 Only local
connections are allowed. Please see
https://chromedriver.chromium.org/security-considerations for
suggestions on keeping MSEdgeDriver safe. MSEdgeDriver was started
successfully.
DevTools listening on
ws://127.0.0.1:1310/devtools/browser/c4e7f6f6-46d3-447c-b26b-3ad231a6122f
[29296:584:1001/203949.853:ERROR:fallback_task_provider.cc(119)] Every
renderer should have at least one task provided by a primary task
provider. If a fallback task is shown, it is a bug. Please file a new
bug and tag it as a dependency of crbug.com/739782.
[29296:26032:1001/203954.115:ERROR:chrome_browser_main_extra_parts_metrics.cc(250)]
crbug.com/1216328: Checking default browser status started. Please
report if there is no report that this ends.
[29296:584:1001/203954.143:ERROR:profile_manager.cc(1057)] Cannot
create profile at path
C:\Users\NibblyPig\AppData\Local\Microsoft\Edge\User Data\Default
[29296:584:1001/203954.143:ERROR:profile_manager.cc(2010)] Cannot
create profile at path
C:\Users\NibblyPig\AppData\Local\Microsoft\Edge\User Data\Default
[29296:26032:1001/203954.176:ERROR:chrome_browser_main_extra_parts_metrics.cc(254)]
crbug.com/1216328: Checking default browser status ended.
The code then crashes with OpenQA.Selenium.WebDriverException: 'unknown error: net::ERR_CONNECTION_TIMED_OUT
I've tried googling the fallback task provider error and also looking at the profile error, but there is very little information and I am at a loss of what to do.
I wonder if anyone could advise what steps I might take to get this working.
First, if you use WebDriver with Selenium 3, the Selenium Tools for Microsoft Edge package must be installed.
Did you import the wrong package? Make sure it is using Microsoft.Edge.SeleniumTools; not using OpenQA.Selenium.Edge;.
This is my simple test, and it works well:
public static void Main() {
var options = new EdgeOptions();
options.UseChromium = true;
options.BinaryLocation = #"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";
var driverPath = #"C:\Users\Administrator\Desktop";
var driver = new EdgeDriver(driverPath, options);
driver.Url = "https://www.google.com/";
}
Note: Please modify the path parameters according to your own situation.
I need to setup phantomjs to use a proxy. I have found many examples for java, javascript/node.js, etc. But none for c# using selenium. I need to set a global proxy and be able to change it without restarting the driver. I believe it would be under driver.ExecutePhantomJS() but I also cant find what phantomjs script I would run to change the global proxy.
When creating the service:
OpenQA.Selnium.Proxy myproxy = new Proxy();
myproxy.httpProxy = ip +":"+port;
driverservice.AddAdditionalCapability(CapabilityType.Proxy, myproxy);
After driver is running to change the proxy:
driver.ExecutePhantomJS("phantom.setProxy('"+ip+"', "+port+", 'http', '', '');")
I am trying to use the Selenium HtmlUnit driver in C# tests. As far as I know, the only way to use the HtmlUnit driver in C# is through Selenium server and the RemoteWebDriver:
var driver = new OpenQA.Selenium.Remote.RemoteWebDriver(
OpenQA.Selenium.Remote.DesiredCapabilities.HtmlUnitWithJavaScript());
However, I also need to use NTLM authentication. Using the non-remote driver in Java, it can apparently be configured like this:
WebDriver driver = new HtmlUnitDriver() {
protected WebClient modifyWebClient(WebClient client) {
// Does nothing here to be overridden.
DefaultCredentialsProvider creds = new DefaultCredentialsProvider();
creds.addNTLMCredentials("userName", "password", null, -1, "myComputerName", "myDomain");
client.setCredentialsProvider(creds);
return client;
}
}
(Source: https://groups.google.com/forum/#!topic/webdriver/ktIWIs5m0mQ)
But this obviously does not solve my problem since I am using C#. How can I do that ? (I can use Chrome successfully, but I would like to use HtmlUnit for speed).
Thanks !
In order to pass credentials you need to overload the modifyWebClient of the HtmlUnitDriver, as you saw in the discussion link1.
For the .NET developer the only way to use the HtmlUnitDriver is via the RemoteWebDriver, and based on the discussion HtmlUnit wrapper for .NET2 the developers chose not to expose all of the HtmlUnit driver classes:
I'm loathe to take any more dependencies in the .NET
bindings... If you're dead-set on using HtmlUnit as your headless browser of choice, you can always use it via the RemoteWebDriver
Therefore you cannot use NTLM, or any other credential method, with the RemoteWebDriver.
If you were willing to do and maintain the work you could convert all the HtmlUnit code as detailed in the second link of #JasonPlutext's answer3.
The original sample appears to be from the selenium FAQ.
Linked to from Is there an HtmlUnitDriver for .NET? here on SO.
I'm trying to instantiate an InternetExplorerDriver in C#, and every time I do I get the following error message:
System.InvalidOperationException : Unexpected error launching Internet Explorer. Protected Mode must be set to the same value (enabled or disabled) for all zones. (NoSuchDriver)
Now I'm not sure how to sort this out, but the line of code that triggers the error in question is:
IWebDriver driver = new InternetExplorerDriver();
The documentation for InternetExplorerDriver suggests that I can pass in an ICapabilities object in an overloaded constructor, but that only has the properties BrowserName, IsJavaScriptEnabled, Platform and Version. None of these seem to suggest that they can solve the issue.
Is there something I need to do within the implementation to sort this out?
Or do I have to modify some settings within IE9 itself?
For reference, if your wish to override the security options here's the c# code:
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
namespace SeleniumTests
{
[TestFixture]
public class Test
{
private IWebDriver driver;
[SetUp]
public void Setup()
{
var options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
driver = new InternetExplorerDriver(options);
}
}
}
Update:
My previous answer used an older version of Selenium 2.0, I've now updated the code to work against Selenium DotNet-2.21.0 and included the correct namespaces.
Internet Explorer defines four zones, each with a different security level and the ability to enable or disable Protected Mode. The error message is trying to tell you that Protected Mode must either be disabled or enabled for all zones because of a limitation in Selenium's InternetExplorerDriver.
For more details, see the defect report in Selenium's issue tracker and the screenshot of Internet Explorer security options.
This should solve the problem:
InternetExplorerOptions options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
IWebDriver driver = new InternetExplorerDriver(options);
Aleh's Answer resolved the issue for me, but I found I also needed to specify the file path for the location of the IEDriverServer. Just posting in case anyone else runs into a similar issue.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
namespace SeleniumTest
{
class Program
{
static void Main(string[] args)
{
InternetExplorerOptions options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
IWebDriver driver = new InternetExplorerDriver("C:\\Selenium", options);
driver.Navigate().GoToUrl("http://www.stackoverflow.com");
}
}
}
Refer link: -
https://intensetesting.wordpress.com/2014/09/16/error-80070012-unexpected-error-launching-spoon-based-internet-explorer/
If you upgrade or degrade the native IE browser which was installed during OS installation it will not allow opening the spoon browsers. Every time we need to make the default IE browser then it will work.
Suppose while you installed the OS the default IE version is IE8 and you upgraded to IE9 for some purpose. In this case it won’t allow navigating any application in the Spoon browsers (only browser will open up) and it will simply throw the error message like “Unexpected error launching internet explorer IELaunchURL error returned 80070012”.
I found the following worked for me (none of the answers above worked)
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.SetCapability(InternetExplorerDriver.IntroduceInstabilityByIgnoringProtectedModeSettings, true);
driver = new InternetExplorerDriver(desiredCapabilities);
I found that it worked, but I also recieved an "(Unexpected Alert Open)" when I tried to run a test, which of all things, turned out I had to disable the IE developer toolbar.
I had similar problem on a server that was built and I had no way of changing the protected mode. It was disabled by the system administrator. Even when I logged in with an admin account, I was unable to change the protected mode. However, I was able to run selenium with no problem.