Comments (6)
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.
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.
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.
Can an action retry a whole task list? IE: this failed, retry?
from chromedp.
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.
Looks like the discussion here ended long ago, so I'm closing.
from chromedp.
Related Issues (20)
- How can I get continuous perfect images using screenshots
- how to use proxy https
- when use chromedp.Evaluate, how can I get the promise error info ?
- Navigate Hangup with custom url scheme HOT 1
- page.StopLoading() cannot stop navigate
- chrome failed to start with no detail error
- Screenshot from remote browser
- context canceled even with new context HOT 1
- Download events being omitted on the page level but chromedp listens for it on the Browser level HOT 1
- Image not showing up in header
- Can't use proxy and open multiple tabs ?
- Target.targetCrashed > errorCode 11 with chromedp.Navigate() in Docker container environnement HOT 7
- Is it possible to use the net/http client in chromedp ? HOT 1
- GetOuterHTML().WithPierce(true) not returning <iframe> contents
- How to execute JavaScript in a specified context? HOT 1
- How to set the state of ShadowDOM from closed to open?
- Question: condition for set FooterTemplate
- Is it possible to capture error messages related to CORS, CSP violations, mixed-content violations, etc.?
- Can I Capture Raw HTTP Data?
- How to start chrome in arm environment?Are there any other plans?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chromedp.