Skip to content

Commit

Permalink
feat: Add active element support
Browse files Browse the repository at this point in the history
  • Loading branch information
electricbubble committed May 16, 2021
1 parent 67053f3 commit caeedcd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
21 changes: 21 additions & 0 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,27 @@ func (d *Driver) FindElement(by BySelector) (elem *Element, err error) {
return d._findElement(by.getMethodAndSelector())
}

func (d *Driver) ActiveElement() (elem *Element, err error) {
// register(getHandler, new ActiveElement("/wd/hub/session/:sessionId/element/active"))
var rawResp RawResponse
if rawResp, err = d.executeGet("/session", d.sessionId, "/element/active"); err != nil {
return nil, err
}
var reply = new(struct{ Value map[string]string })
if err = json.Unmarshal(rawResp, reply); err != nil {
return nil, err
}
if len(reply.Value) == 0 {
return nil, errors.New("no such element")
}
var id string
if id = elementIDFromValue(reply.Value); id == "" {
return nil, fmt.Errorf("invalid element returned: %+v", reply)
}
elem = &Element{parent: d, id: id}
return
}

type Condition func(d *Driver) (bool, error)

func (d *Driver) _waitWithTimeoutAndInterval(condition Condition, timeout, interval time.Duration) (err error) {
Expand Down
24 changes: 24 additions & 0 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -928,3 +928,27 @@ func TestDriver_WaitWithTimeoutAndInterval(t *testing.T) {
}

}

func TestDriver_ActiveElement(t *testing.T) {

driver, err := NewUSBDriver()
if err != nil {
t.Fatal(err)
}
defer func() {
_ = driver.Dispose()
}()

SetDebug(true)

element, err := driver.ActiveElement()
if err != nil {
t.Fatal(err)
}

SetDebug(false)

if err = element.SendKeys("test"); err != nil {
t.Fatal(err)
}
}

0 comments on commit caeedcd

Please sign in to comment.