Saturday, May 24, 2025
HomeGolangChromedp ingredient apparently not clicked - Getting Assist

Chromedp ingredient apparently not clicked – Getting Assist


I’m utilizing chromedp to open a brand new tab (context) for a given hyperlink and more often than not, it really works fantastic.

However, what I’m making an attempt to grasp is why it generally doesn’t. By doesn’t, I imply that I’ve log messages earlier than and after clicking the hyperlink and so far as I can inform, chromedp executes the clicking with out error or delay:

2025/05/02 07:30:00 -0400 INF clicking: //*[@id=“home-screen”]/div[2]/part[5]/div[5]/div/ul/li[2]/a[1]
2025/05/02 07:30:00 -0400 INF clicked
2025/05/02 07:38:25 -0400 INF new occasion


targetElementXpath := fmt.Sprintf("//*[@id="home-screen"]/div[2]/part[5]/div[5]/div/ul/li[%d]/a[1]", i.Index)
	targetIDChannel := chromedp.WaitNewTarget(i.session.ctx, matchTabWithNonEmptyURL)

	timeLimitedCtx, timeLimitedCancel := context.WithTimeout(i.session.ctx, 5*time.Second)
	defer timeLimitedCancel()

	log.Data().Msgf("clicking: %s", targetElementXpath)
	err := chromedp.Run(timeLimitedCtx, chromedp.Click on(targetElementXpath))
	if err != nil {
		return err
	}

	log.Data().Msg("clicked")
	newInstance, newCancelFunc := chromedp.NewContext(i.session.ctx, chromedp.WithTargetID(<-targetIDChannel))
	i.ctx = newInstance
	i.cancel = newCancelFunc

	log.Data().Msg("new occasion")
	return nil

This can be a snippet of the code that’s producing the message above. From the logs, we are able to discern that it took 8 minutes and 25 seconds to return. That point is once I manually clicked the hyperlink thereby launching the brand new tab.

  1. how would chromedp click on a component instantly, but no tab was really launched? As I’m utilizing the distant developer choice, I can see the web page and though chrome is far sooner than my eyes, the weather have been there for me to see. I’ve had errors if the ingredient didn’t exist.
  2. individually, I have to refactor the blocking code for the way lengthy I need to wait to obtain the brand new session. Maybe that may alleviate drawback #1 as a result of if for some cause chromedp didn’t really set off the clicking, then making an attempt once more would possibly get it working.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments