sourcegraph / go-selenium Goto Github PK
View Code? Open in Web Editor NEWSelenium WebDriver client for Go
Home Page: https://sourcegraph.com/github.com/sourcegraph/go-selenium
License: Other
Selenium WebDriver client for Go
Home Page: https://sourcegraph.com/github.com/sourcegraph/go-selenium
License: Other
It supports chrome profile? Can you please provide a example, if it does.
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("")
When I click on a link in my test, it opens a new tab. I want ChromeDriver to then focus on that tab. how do i do ?
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.
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
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
?
please help me
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
How to set proxy?
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?
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()
?
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
}
}`
Please remove hard-coded package url as it is not valid.
package selenium // import "sourcegraph.com/sourcegraph/go-selenium"
Taking screenshot always return 24 bytes of black image.
This happens for both Chrome and Firefox browsers.
--- FAIL: TestScreenshot-5 (13.10 seconds)
remote_test.go:562: unknown error
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)
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:
Greetings! It looks like this project is no longer being developed while upstream (tebeka/selenium
) is looking very active.
Are there any plans to develop this package further or is it dead? ๐
--- FAIL: TestAddCookie-5 (12.20 seconds)
remote_test.go:435: Can't find new cookie
Screenshot() can return io.Reader instead of byte array to give user more control over data
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.
The status code is 13 and complains about a "null externalid" session.
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 ...
}
The /sessions JsonWireProtocol command is not implemented, so one session cannot be aware of other sessions.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.