1

I'm attempting to use chromedp to log into a dashboard. the action on the form is action="javascript:void(0);". When submit is pressed a number of JS functions kick off, with the end result producing the url; the action updated and the submit process continues.

looking at the log, chromedp is using "javascript:void(0);" as the action, so the process is in a continuous loop looking app-sidebar-navigation-menu__item__label. login() is the relevant function:

func login(cfg *config, url, username, password string, res *string) chromedp.Tasks {
   return chromedp.Tasks{
      chromedp.Navigate(url),
      chromedp.WaitVisible(#Email, chromedp.ByID),
      chromedp.WaitVisible(#Password, chromedp.ByID),
      chromedp.SendKeys(#Email, username, chromedp.ByID),
      chromedp.SendKeys(#Password, password, chromedp.ByID),
      chromedp.Submit(#Email, chromedp.ByID),
      chromedp.WaitVisible(.app-sidebar-navigation-menu__item__label, chromedp.BySearch),
      chromedp.Click(.app-sidebar-navigation-menu__item__label, chromedp.BySearch),
      chromedp.Text(.app-sidebar-navigation-menu__item__label, res, chromedp.BySearch),
    }
}

I tried to add a sleep(), but I don't think I'm using it in the correct way:

...

chromedp.Submit(#Email, chromedp.ByID, chromedp.After(func(i context.Context, n ...*cdp.Node) error {
chromedp.Sleep(5 * time.Second)
return nil
})),

...

I do plan to take a look at chromedp.ListenTarget to see if that's a reasonable route, but I'm hoping this is a straightforward solution (and it not, Id need some help with ListenTarget);

I also opened this as an issue on chromedp's github repo; still waiting on a comment.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Ian
  • 21
  • 1
  • Sleeping is almost never a solution. Still, why not try `time.Sleep()`? – kostix Jul 21 '20 at 14:22
  • I don't believe I'm using sleep [ `chromedb.Sleep()` or `time.Sleep()` ] correctly. I tried `time.Sleep(large_number)` but `chromedp.Submit()` still proceeded; using javascript:void() as the action's value...and I agree, sleeping is never the final solution but I'm grasping here to get something to work. – Ian Jul 21 '20 at 20:42
  • 2
    I migrated to [go-rod](https://github.com/go-rod/rod); which is a much, much cleaning implementation / i-face. The page functions wrap a retry until the element is visible or it times out...Got what I needed (with clear-er examples) in under 10 mins. – Ian Jul 22 '20 at 16:01
  • @lan thank you for your comment. All day i lost with chromedp, but rod so understandeble, it's treasure – Billizzard Nov 20 '21 at 17:51

0 Answers0