Skip to content

Commit

Permalink
Merge pull request #33 from DanielFillol/daniel
Browse files Browse the repository at this point in the history
nav log on Switch
  • Loading branch information
DanielFillol authored Jul 12, 2024
2 parents 0b2405c + 393dcf5 commit 8c89edc
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions goSpider.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ func (nav *Navigator) GetElementAttribute(selector, attribute string) (string, e

// SwitchToFrame switches the context to the specified iframe.
func (nav *Navigator) SwitchToFrame(selector string) error {
nav.Logger.Println("Switching to frame", selector)

// Wait for the iframe to be visible
err := nav.WaitForElement(selector, nav.Timeout)
if err != nil {
Expand All @@ -139,11 +141,14 @@ func (nav *Navigator) SwitchToFrame(selector string) error {
return fmt.Errorf("failed to switch to iframe: %v", err)
}

nav.Logger.Println("SwitchToFrame", selector, "successfully")
return nil
}

// SwitchToDefaultContent switches the context back to the main content from an iframe context.
func (nav *Navigator) SwitchToDefaultContent() error {
nav.Logger.Println("Switching to default content")

// Switch back to the main content
err := chromedp.Run(nav.Ctx,
chromedp.Tasks{
Expand All @@ -161,6 +166,7 @@ func (nav *Navigator) SwitchToDefaultContent() error {
return fmt.Errorf("failed to switch to default content: %v", err)
}

nav.Logger.Println("Switch to default content successfully")
return nil
}

Expand Down

0 comments on commit 8c89edc

Please sign in to comment.