Giter Site home page Giter Site logo

Url navigation change about chromedp HOT 6 CLOSED

chromedp avatar chromedp commented on May 14, 2024
Url navigation change

from chromedp.

Comments (6)

kenshaw avatar kenshaw commented on May 14, 2024

To be honest, the best way to accomplish a lot of this would be to monitor the Network domain events. The model we have with chromedp though, doesn't monitor Network events, but uses the Page and DOM events. There's "yet another dimension" though, for monitoring above the "Page" level that can only be surfaced through monitoring Network events.

Timing is definitely difficult; you'll see this problem exists more or less in all the various mechanisms for testing/driving browsers. It's difficult to give a general answer that you would always do XYZ, as every page/site is so different, that there's no real catchall. Typically, however, we use WaitNotVisible and then WaitVisible to essentially wait for page-level changes. Since in the ways that we use chromedp, we're not monitoring the low-level Network events.

from chromedp.

clanstyles avatar clanstyles commented on May 14, 2024

So in this exact instance, there's no direct element that identifies this unique page. There is unique content on the page, but "WaitVisible" for specific text isn't accessable.

Maybe make the following externally accessable? Or wrap it in some Action we can then chain to WaitVisible?

	textJS = `(function(a) {
		var s = '';
		for (var i = 0; i < a.length; i++) {
			if (a[i].offsetParent !== null) {
				s += a[i].textContent;
			}
		}
		return s;
	})($x('%s/node()'))`

Right now I'm trying to do something like this

	to := time.Second * 5
	found := false

	for {
		// err := chromedp.ActionFunc(func(ctx context.Context, h cdp.Handler) error {
		fn := chromedp.QueryAfter(".content .contentblock .subline span", func(ctx context.Context, h cdp.Handler, nodes ...*cdp.Node) error {
			if len(nodes) == 0 {
				return nil
			}

			for _, node := range nodes {
				var txt string
				if err := chromedp.EvaluateAsDevTools(fmt.Sprintf(textJS, node.FullXPath()), &txt).Do(ctx, h); err != nil {
					return err
				}

				if strings.ContainsAny(txt, "Thank you") {
					found = true
				}
			}

			return nil
		})

		if err := m.chrome.Run(context.Background(), fn); err != nil {
			panic(err)
		}

		if found {
			return true
		}

		time.Sleep(to)
	}

This code obviously has a bunch of flaws and possible dead locks.

How would I monitor the nextwork events?

from chromedp.

clanstyles avatar clanstyles commented on May 14, 2024

The real problem is, even if I run this code, it can happen so fast that knowing if ti SHOULD run becomes the issue. The page needs to have been loaded or some javascript needs to have been executed.

For example some background ajax that says that an input is invalid.

from chromedp.

clanstyles avatar clanstyles commented on May 14, 2024

Can an action retry a whole task list? IE: this failed, retry?

from chromedp.

kenshaw avatar kenshaw commented on May 14, 2024

Can an action retry a whole task list? IE: this failed, retry?

No, but there's an interesting idea there in terms of a high level action that might make sense. I'll think about it, and let me see about putting something like that in.

So in this exact instance, there's no direct element that identifies this unique page. There is unique content on the page, but "WaitVisible" for specific text isn't accessable.

As far as Chrome is concerned, there's no difference between text / or some other node. You just need to know how to write your selectors. You can do it with either CSS or XPath.

It would be something like this: .//*[contains(text(),"search text")]. If you use this with WaitVisible, then you would end up waiting for the node, as the visibility check that is performed is almost identical.

If you need to run javascript, btw, just use the Eval actions.

from chromedp.

mvdan avatar mvdan commented on May 14, 2024

Looks like the discussion here ended long ago, so I'm closing.

from chromedp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.