I'm trying to automate a test where I need to upload a file, but I keep getting that the file can't be found.
I found in Selenium page that, for other languages, we have to use a Local File Detector so that the file that's in my computer are sent to the remote server.
The Local File Detector allows the transfer of files from the client machine to the remote server.
But I can't find any function related to that in Go.
I've tried the SendKeys function:
element, err := crediya.el.FindElement(selenium.ByID, "file")
if err != nil {
return fmt.Errorf(errors.Selenium.ElementNotFound+"\n%w", err)
}
if err = element.SendKeys(path); err != nil {
return fmt.Errorf(errors.Selenium.SendKeysFailure+"\n%w", err)
}
but I keep getting:
"unknown error - 61: invalid argument: File not found : "
Note: the element is an input of file type.
Thank you, in advance, for any help provided.
Can someone, please, help me?
Related
I'm developing a Go app on a GCP project and I'm using google cloud logging service. I'm having problems in running the app since it's saying that I have invalid authentication credentials when I'm using a service account json key.
Here's the code snippet having the error:
c, cErr := Load(".env")
if cErr != nil {
log.Fatalf("could not load config: %s", cErr)
return
}
// initializes logger which writes to stdout
ctx := context.Background()
opt := option.WithCredentialsFile(c.GoogleApplicationCredentials);
loggerClient, clientErr := logging.NewClient(ctx, "poc-projects-01", opt)
if clientErr != nil {
log.Fatal(clientErr)
}
And here's the definition of the Load() function:
func Load(file string) (*Config, error) {
viper.SetConfigFile(file)
viper.AddConfigPath(".")
viper.AutomaticEnv()
if err := viper.ReadInConfig(); err != nil {
return nil, err
}
c := &Config{
GoogleApplicationCredentials: viper.GetString("GOOGLE_APPLICATION_CREDENTIALS"),
}
return c, nil
}
I have a .env file with the following content:
GOOGLE_APPLICATION_CREDENTIALS=json/path-to-json.json
I don't know why it's saying token expired even though this is the only service account json key I have on GCP, and on my local machine.
Can you run gcloud auth application-default login and make sure you have that set to the right project.
Check whether GOOGLEAPPLICATIONSCREDENTALS is set with valid JSON key and the environment variable are correctly set, for checking run the below command
echo $GOOGLE_APPLICATION_CREDENTIALS
If the command does not return the correct path to the JSON key, you can set the environment variable with this command:
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/json/key.json
Once you have verified that the JSON key is valid and the environment variable is correctly set, you should be able to run your application.Alternatively, you can try to delete the .env file and then recreate it with the service account json key, which should re-generate the token and make it valid.
Attaching troubleshooting documentation for reference.
I have selenium in docker container(selenoid from aerocube) and selenium library for golang from tebeka.
I can't find any examples that show how to run chrome in a remote selenium with the extension (literally only for go)
I even found function in library which do it, but I did not found example of code where It was used.
(https://pkg.go.dev/github.com/tebeka/selenium#v0.9.9/chrome#Capabilities.AddExtension)
caps := selenium.Capabilities{"browserName": "chrome", "browserVersion": "103.0"}
driver, err := selenium.NewRemote(caps, "http://127.0.0.1:4444/wd/hub")
if err != nil {
fmt.Printf("create selenium session error: %v\n", err)
return
}
defer driver.Quit()
driver.Get("https://www.google.com/")
driver.Close()
I want to use the modheader extention, but I get the same question, and i solved it.
Step 1: Get your chrome extention (.crx) file
In my case, i find the modheader document,and get download link from the page.
https://docs.modheader.com/advanced/selenium-webdriver
Download the .crx file to you project.
the .crx download page
Download link
https://github.com/modheader/modheader_selenium/raw/main/chrome-modheader/modheader.crx
Note: Web browser maybe block the download by policy, use the "wget" command get the
file.
block by browser
wget the file
If you want to get other extention , use the follow CRX Extracti/Downloader can help you.
CRX Extracti link
CRX Extracti/Downloader webpage
Step 2: Use the Code loding the extention
package main
import (
"fmt"
"os"
"github.com/tebeka/selenium"
"github.com/tebeka/selenium/chrome"
)
const (
port = 8080
)
func main() {
opts := []selenium.ServiceOption{
// Enable fake XWindow session.
// selenium.StartFrameBuffer(),
selenium.Output(os.Stderr), // Output debug information to STDERR
}
_, err := selenium.NewChromeDriverService("../your_driver_path/chromedriver.exe", port, opts...)
if err != nil {
panic(err)
}
caps := selenium.Capabilities{"browserName": "chrome"}
var cap_ext chrome.Capabilities
// add your extention by crx file
cap_ext.AddExtension("./modheader.crx")
caps.AddChrome(cap_ext)
wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://127.0.0.1:%d/wd/hub", port))
// Using api to setting modheader
// add header
wd.Get("https://webdriver.modheader.com/add?test=ModHeader%20Test")
}
Step 3: Setting the extention
Modheader extention supply api to setting.
Example :
wd.Get("https://webdriver.modheader.com/add?test=ModHeader%20Test")
Step 4: Result
Loading and setting extention successful
I hope that I can help. Good Luck.
What I'm trying to do:
Build a package (later usage) that provides a method to execute a get-request to any page through a given socks5 proxy.
My problem:
When ever I try to request a page with SSL (https) I get the following error:
Error executing request Get https://www.xxxxxxx.com: socks connect tcp 83.234.8.214:4145->www.xxxxxxx.com:443: EOF
However requesting http://www.google.com is working fine. So there must be a problem with the SSL connection. Can't imagine why this isn't working as I'm not very experienced with SSL-connections. End of file makes no sense to me.
My current code:
func main() {
// public socks5 - worked when I created this question
proxy_addr := "83.234.8.214:4145"
// With this address I get the error
web_addr := "https://www.whatismyip.com"
// Requesting google works fine
//web_addr := "http://www.google.com"
dialer, err := proxy.SOCKS5("tcp", proxy_addr, nil, proxy.Direct)
handleError(err, "error creating dialer")
httpTransport := &http.Transport{}
httpClient := &http.Client{Transport: httpTransport}
httpTransport.DialTLS = dialer.Dial
req, err := http.NewRequest("GET", web_addr, nil)
handleError(err, "error creating request")
httpClient.Timeout = 5 * time.Second
resp, err := httpClient.Do(req)
handleError(err, "error executing request")
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
handleError(err, "error reading body")
fmt.Println(string(b))
}
func handleError(err error, msg string) {
if err != nil {
log.Fatal(err)
}
}
So what am I missing in here to deal with ssl-connections?
Thank you very much.
Edit 1:
In case someone would think this is an issue with whatismyip.com I've done some more tests:
https://www.google.com
EOF error
https://stackoverflow.com
EOF error
https://www.youtube.com/
EOF error
Connection between your program and your socks5 proxy goes not through SSL/TLS
So you should change line
httpTransport.DialTLS = dialer.Dial
to
httpTransport.Dial = dialer.Dial
I checked https://www.whatismyip.com and https://www.google.com.
URLs are downloaded fine.
For test I set up 3proxy service on my server, test your code with fixed line and check 3proxy logs.
All made requests was in proxy server logs.
If you need more help - please let me know, I'll help
Things to notice:
Socks5 proxies need to support SSL connections.
The code from the question won't work with this answer as the proxy (used in the code) isn't supporting SSL connections.
I'm starting to learn golang and I'm trying to make a simple http client that will get a list of virtual machines from one of our oVirt clusters. The API that I'm trying to access has a self-signed certificate (auto generated during the cluster installation) and golang's http.client encounters a problem when serializing the time from the certificate. Below you can find the code and the output.
package main
import (
"fmt"
"io/ioutil"
"net/http"
"crypto/tls"
)
func do_request(url string) ([]byte, error) {
// ignore self signed certificates
transCfg := &http.Transport{
TLSClientConfig: &tls.Config {
InsecureSkipVerify: true,
},
}
// http client
client := &http.Client{Transport: transCfg}
// request with basic auth
req, _ := http.NewRequest("GET", url, nil)
req.SetBasicAuth("user","pass")
resp, err := client.Do(req)
// error?
if err != nil {
fmt.Printf("Error : %s", err)
return nil, err
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
return []byte(body), nil
}
func main() {
body, _ := do_request("https://ovirt.example.com/")
fmt.Println("response Status:", string(body))
}
and the error when I'm trying to compile:
$ go run http-get.go
Error : Get https://ovirt.example.com/: tls: failed to parse certificate from server: asn1: time did not serialize back to the original value and may be invalid: given "141020123326+0000", but serialized as "141020123326Z"response Status:
Is there any way to ignore this verification? I tried making a request using other programming languages (python, ruby) and skipping insecure certificates seems to be enough.
Thank you!
PS: I know the proper solution is to change the certificate with a valid one, but for the moment I cannot do this.
Unfortunately, you've encountered an error that you cannot get around in Go. This is buried deep in the cypto/x509 and encoding/asn1 packages without a way to ignore. Specifically, asn1.parseUTCTime is expecting the time format to be "0601021504Z0700", but your server is sending "0601021504+0000". Technically, that is a known format but encoding/asn1 does not support it.
There are only 2 solutions that I can come up with that do not require a code change for golang.
1) Edit the encoding/asn1 package in your go src directory and then rebuild all the standard packages with go build -a
2) Create your own customer tls, x509 and asn1 packages to use the format your server is sending.
Hope this helps.
P.S. I've opened an issue with the Go developers to see if it can resolved by them at some later point Issue Link
Possible ASN1 UtcTime Formats.
Im using 000webhost as a way to host my portfolio of websites. However Im getting this error thrown in which doesn't happen to me on localhost.
Notice (8): Undefined index: Upload [APP/Controller/UploadsController.php, line 32]
This is the code it seems to be referring to,
public function add() {
$this->render();
if($this->request->is('post')){
$file = $this->request->data['Upload']['file'];
if($this->Upload->save($this->data) && move_uploaded_file($file['tmp_name'],APP.'webroot/files/uploads'.DS.$this->Upload->id.'.mp4'))
{
$this->Session->setFlash('<p class="uploadflash">The upload has been saved</p>', true);
$this->redirect(array('controller'=>'Uploads', 'action' => 'watch', $this->Upload->id));
} else {
$this->Session->setFlash('<p class="loginerror">The upload could not be saved, mp4 files can be saved only.</p>', true);
}
}
}
Any ideas as to why this is happening?
Also in addition my Elements are not showing up on this online hosting either?
I get thrown this error on the page
Element Not Found: Elements/uploads/recentuploads.ctp
Does anyone else seem to have this problem??
Upon further inspection I have found that the server does not allow file upload sizes to exceed 2mb, in this instance PHP throws the error above.