Can not Use Selenium Driver With Golang Agouti Package - docker

I use agouti package in golang. I run selenium docker image, and create a new web driver with the following command:
capabilities := agouti.NewCapabilities().Browser("chrome").With("javascriptEnabled")
command := []string{"java", "-jar", "selenium-server.jar", "-port", "4444"}
driver = agouti.NewWebDriver("http://127.0.0.1:4444/wd/hub", command, agouti.Desired(capabilities))
I create a new page and try to set a value of an element in this page. I find element with xpath by using the following command:
var selection = page.FindByXPath(xpath)
Then try to send key with SendKeys() method of Agouti, but it does not set the value to the element. I tried to send an API call to the selenium by using the JSON Wire Protocol of the selenium. In this case, I need the id of the element to send the request. I try to obtain the id of the element with the following code:
elems, _ := selection.Elements()
id := elems[0].ID
But when I print the id, I saw that it is empty. So my request is not sent. The error I get is like following:
request unsuccessful: Unable to execute request for an existing session: POST /session/bba01dd19db3a063304a40b59b4cefb7/element//value
The main reason is of the error is that the id of the element is empty.
Btw, when I use chrome driver it works properly
args = append(args, "disable-blink-features=AutomationControlled")
chromeOpts := agouti.ChromeOptions("args", args)
options = append(options, chromeOpts)
driver = agouti.ChromeDriver(options...)
I dont understand why i can not use the selenium in agouti, and why the id of the element is empty. I hope that I explain my problem.
Thanks

Related

Saving a docke image to a file with the Docker Client in go

I'm trying to create a tool that gathers dependencies and I want it to gather some docker images. I'm using the docker client go module which provides ImagePull and ImageSave methods where the image save method should return io.ReadCloser stream. I'm having trouble with invoking the method.
I'm trying to call it like so:
io, err := cli.ImageSave(ctx, ["docker.io/library/alpine"])
but I'm getting an error where the compiler is expecting:
expected type, found ')'
I'm not really sure what I'm doing wrong here since the method should receive the context and a string array that represents the image on the host which I want to save...
Thanks in advance :)
You should call the mothod like this:
io, err := cli.ImageSave(ctx, []string{"docker.io/library/alpine"})
:)

DWS insert variable values on debug

I'm facing a problem I can't find the workaround...
I have a script which take some parameter data before execution. When I run it my code looks like:
Exec := FProgram.CreateNewExecution;
Exec.BeginProgram;
Exec.Info.ValueAsString['varName'] := 'varValue';
Exec.RunProgram(0);
Exec.EndProgram;
It runs just fine. But if I want to debug the script I do something like this:
Exec := FProgram.CreateNewExecution;
Exec.BeginProgram;
Exec.Info.ValueAsString['varName'] := 'varValue';
Debugger.BeginDebug(Exec);
Debugger.EndDebug;
Being Debugger a TdwsDebugger class, I get "runtime error: script is already running".
If I don't assign variables values before debugging everything is ok.
Any hints?
I managed to solve it using the TDelphiWebScript component events. Using OnExecutionStarted does not work either. I modified the code and added OnAfterExecutionStarted event, then I added the variables on the new event and everything is ok now.

How can I prevent Chromium from writing to the console?

I'm making a very simple Delphi console application ({$APPTYPE CONSOLE}) with a single TChromiumWindow on the main form. The purpose of the application is to retrieve a webpage, process the HTML and output some JSON to the console. This can not be done using plain HTTP requests due to the nature of the webpage, which requires running some javascript as well.
Everything works as expected, except for one problem. The chromium components output some error messages to the console as well, which makes my JSON invalid! For example, I always get the following two error messages on startup:
[0529/133941.811:ERROR:gpu_process_transport_factory.cc(990)] Lost UI shared context.
[0529/133941.832:ERROR:url_request_context_getter_impl.cc(130)] Cannot use V8 Proxy resolver in single process mode.
Of course the best solution would be to not get any error messages in the first place, but for several reasons (which mostly have to do with company legacy code) I can't for example disable single process mode.
So the next best thing would be to keep these error messages from being printed to the console. I've tried setting
GlobalCEFApp.LogSeverity := LOGSEVERITY_DISABLE;
but that didn't help. Specifying a logfile using GlobalCEFApp.LogFile doesn't help either.
So how can I prevent the Chromium components from writing to the console at all?
The TChromium component provides an OnConsoleMessage event with signature :
TOnConsoleMessage = procedure(Sender: TObject; const browser: ICefBrowser;
const message, source: ustring; line: Integer;
out Result: Boolean) of object;
If you handle this event and set the Result variable to true the message output to the console is suppressed.
Set LogSeverity to LogSeverity.Fatal or n other desired.
var settings = new CefSettings()
{
//By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache"),
//Set log severity to showup only fatal errors.
LogSeverity = LogSeverity.Fatal,
};
//Autoshutdown when closing
CefSharpSettings.ShutdownOnExit = true;
//Perform dependency check to make sure all relevant resources are in our output directory.
Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);

Drupal Curl, $GET

I am creating a Drupal 7 node from remote. In my server I have a script that uses
now=$(date)
curl --data "date=$now" http://website.com
That is supposed to send the value of $now to the url. In my remote nodecreate.php form I am using
$node->field_date[$node->language][0]['value'] = $_GET['date'];
To set the value of the date field in the node. Problem is that the node is created successfully, but the date is blank.
I have tried other variations such as setting a value to a string in the remote nodecreate.php like this
$date = $_GET['date'];
$node->field_date[$node->language][0]['value'] = $date;
however that did not work either. Anyone got ideas what is wrong here?
You probably should use the following :
$node->field_date[LANGUAGE_NONE][0]['value'] = $date;
I suppose here that you are using translation on node but not translatable fields.

Is it possible to forge post or get request inside casper,run

I have created a webscraping script in casperJs.
What I want is I need to insert the result which i get from the scraping in sql server database.
I am planning to do it by posting the result on server where it inserts in db.
I have tried the below code to test if it can be done inside casper.run
casper.run(function () {
var finalResult = this.evaluate(somefunction, Obj);
this.open('http://www.testserver.com/post.php?q=test').then(function() {
this.echo('GOT it.');
});
It doesnot make the request nor does it echo GOT It.
I am not sure if this is a neat way to do it. I would rather suggest using SpookyJS and SQL server library for NodeJS.
It can be achieved by 2 ways as below:
1) By using the this.open outside .run
2) By running the casper via php script and insert the results in db from there.

Resources