GithubHelp home page GithubHelp logo

sourcegraph / go-selenium Goto Github PK

View Code? Open in Web Editor NEW
367.0 91.0 73.0 292 KB

Selenium WebDriver client for Go

Home Page: https://sourcegraph.com/github.com/sourcegraph/go-selenium

License: Other

Go 100.00%

go-selenium's Issues

Default handle name in case of empty name.

For several functions such as WindowSize(name string) takes window handle name as argument.

This can be confusing at times and should support default value of "current" in case empty string is passed as argument.

// This doesn't work but should work!
webDriver.WindowSize("") 

Xpath

is usage right?

webDriver.FindElement(selenium.ByXPATH, "//div[@Class='pr-in-cn']//span[@Class='prc-dsc']")

This code doesn't work for me.

GetCookies sometimes fails on chromedriver

It seems that when using ChromeDriver (and perhaps other drivers), sometimes the value returned for the cookie's expiry field doesn't deserialize as a uint.

For example:

[
  {
    "domain":".typeform.com",
    "expiry":1475462515.303742,
    "httpOnly":false,
    "name":"__insp_slim",
    "path":"/",
    "secure":false,
    "value":"1443926515303"
},
...
]

Notice how the expiry field has a period followed by a bunch of digits. I'm guessing this is fractions of a second?

I changed the type of Expiry to interface{} in my fork to fix the immediate issue. Maybe there is a way to detect this & handle it better though.

ExecuteScript always returns error "unknown error"

result, err := webDriver.ExecuteScript("document.readyState", nil)
if err != nil {
    fmt.Printf("ERROR executing script: %s\n", err)
}

yields:
ERROR executing script: unknown error

the selenum server log shows
20:29:29.816 WARN - Exception thrown
java.lang.NullPointerException
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:191)
at com.google.common.collect.Iterables.transform(Iterables.java:708)
at org.openqa.selenium.remote.server.handler.ExecuteScript.setJsonParameters(ExecuteScript.java:46)
at org.openqa.selenium.remote.server.rest.ResultConfig.setJsonParameters(ResultConfig.java:309)
at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:193)
at org.openqa.selenium.remote.server.JsonHttpRemoteConfig.handleRequest(JsonHttpRemoteConfig.java:192)
at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:201)
at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:167)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:139)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)

ChromeDriver (v2.3)
selenium-server-standalone-2.35.0.jar
Linux Desktop2012 3.10.9-1-ARCH #1 SMP PREEMPT Wed Aug 21 13:49:35 CEST 2013 x86_64 GNU/Linux

Explicitly waiting for new page to load after Click()

I'm writing a simple page performance tester. I'm trying to fill in a form, issue a Click() on the submit button, and then gather timing information on the page that's returned by the server after the submission.

I'm able to fill the form out (FindElement(), SendKeys()) and I can issue the Click() but I haven't figured out how to wait until the resulting new page is rendered before attempting to gather timings. Is this possible in go-selenium?

Doesn't work with IeDriverServer

The problem is that StartSession returns empty sessionId.
The reason of this behaviour is serialization problem of reply struct. If sessionId is first string of json - it works ok. But IeDriverServer returns it as last param in json, so it not deserialized properly

Element Screenshot

webdriver has define element screenshot, in 18.2: https://www.w3.org/TR/webdriver/#take-element-screenshot

I have try as this:

func (elem *remoteWE) ScreenshotElement() ([]byte, error) {
data, err := elem.parent.stringCommand("/session/%s/element/" + elem.id + "/screenshot")
if err != nil {
	return nil, err
}

return []byte(data), nil
}

But i cannot work, error is 404 Not found, why?

No way to switch to frame parent

I've done SwitchFrame() to switch into an iframe and perform some actions, but then I need to switch out of it again and do something from outside that frame.

The wisdom on the internet seems to be that I either need to pass an integer "0" to switch to the frame with the first index, or call /session/{id}/frame/parent, neither of which seem possible in go-selenium. Would a pull request be accepted which adds SwitchFrameParent()?

Failed to open session: unknown error - 33: Unable to create new service: GeckoDriverService

Selenium server: 3.6.0

Go error:

Failed to open session: unknown error - 33: Unable to create new service: GeckoDriverService
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:40.131Z'
System info: host: 'anboo', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.10.0-35-generic', java.version: '1.8.0_144'
Driver info: driver.version: unknown

Selenium logs:

09:53:06.803 INFO - Binding default provider to: org.openqa.selenium.chrome.ChromeDriverService
09:53:06.804 INFO - Found handler: org.openqa.selenium.remote.server.commandhandler.BeginSession@18a73dae
09:53:06.805 INFO - /session: Executing POST on /session (handler: BeginSession)
09:53:06.808 INFO - Capabilities are: Capabilities {browserName=firefox}
09:53:06.809 INFO - Capabilities {browserName=firefox} matched class org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.firefox.GeckoDriverService)
09:53:06.810 INFO - Capabilities {browserName=firefox} matched class org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)

Code:
`package main

import (
"fmt"
//"sourcegraph.com/sourcegraph/go-selenium"
"github.com/tebeka/selenium"
)

func main() {
var webDriver selenium.WebDriver
var err error
caps := selenium.Capabilities(map[string]interface{}{"browserName": "firefox"})
if webDriver, err = selenium.NewRemote(caps, "http://localhost:4444/wd/hub"); err != nil {
fmt.Printf("Failed to open session: %s\n", err)
return
}
defer webDriver.Quit()

err = webDriver.Get("https://sourcegraph.com/sourcegraph/go-selenium")
if err != nil {
	fmt.Printf("Failed to load page: %s\n", err)
	return
}

if title, err := webDriver.Title(); err == nil {
	fmt.Printf("Page title: %s\n", title)
} else {
	fmt.Printf("Failed to get page title: %s", err)
	return
}

var elem selenium.WebElement
elem, err = webDriver.FindElement(selenium.ByCSSSelector, ".repo .name")
if err != nil {
	fmt.Printf("Failed to find element: %s\n", err)
	return
}

if text, err := elem.Text(); err == nil {
	fmt.Printf("Repository: %s\n", text)
} else {
	fmt.Printf("Failed to get text of element: %s\n", err)
	return
}

}`

Remove hard-coded package url

Please remove hard-coded package url as it is not valid.

package selenium // import "sourcegraph.com/sourcegraph/go-selenium"

Adding Cookie Before Load?

Currently attempting to load a cookie before the loading of the page / browser but having issues. Is this possible or am I doing this wrong? Rather new to golang.

cookie := selenium.Cookie{"domain_splash", "1", "/", ".domain.com", false, 0}
webDriver.AddCookie(&cookie)

How to switch to frame via WebElement?

There is only one function:

/* Switch to frame, frame parameter can be name or id. */
SwitchFrame(frame string) error

But how can I switch to frame if this frame do not have id and name attributes?
For example in Python there is a method that take WebElement as a parameter, looks like:

frame = driver.find_element_by_css_selector("#main iframe")
driver.switch_to.frame(frame)

I don't know JsonWireProtocol, maybe it is possible to do it via WebElement?
Otherwise I can solve this problem via a hack:

  1. find frame tag
  2. add to this tag a uniq id attribute
  3. do SwitchFrame via id

Moving Go source files to selenium/ subdirectory

I am proposing to move the top-level *.go files to a new selenium/ subdirectory so that library users refer to the library by the last path component (selenium) instead of having to guess that go-selenium maps to selenium.

If I don't hear any objections in a week, I'll go ahead and make the change.

Impose read limit for large content/screenshot etc.

It would be nice to have an option to set read limit for large file size.

func (wd *remoteWebDriver) execute(method, url string, data []byte) ([]byte, error) {

    // omitted ...

    buf, err := ioutil.ReadAll(res.Body)
    if err != nil {
        return nil, err
    }

    // omitted ...

}

to

func (wd *remoteWebDriver) execute(method, url string, data []byte) ([]byte, error) {

    // omitted ...

    limit := 1 << 20 // 1MB limit
    buf, err := ioutil.ReadAll( io.LimitReader(r.Body, limit) )
    if err != nil {
        return nil, err
    }

    // omitted ...

}

/sessions not implemented

The /sessions JsonWireProtocol command is not implemented, so one session cannot be aware of other sessions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.