mirror of
				https://github.com/MontFerret/ferret.git
				synced 2025-10-30 23:37:40 +02:00 
			
		
		
		
	Feature/#230 xpath (#322)
* Implemented XPath for CDP driver * Added XPATH function * Added e2e tests for CDP * Fixed linting issues * Added support of XPath to HTTP driver * Fixed linting issues
This commit is contained in:
		| @@ -64,6 +64,7 @@ func NewLib() map[string]core.Function { | ||||
| 		"WAIT_STYLE_ALL":    WaitStyleAll, | ||||
| 		"WAIT_NO_STYLE_ALL": WaitNoStyleAll, | ||||
| 		"WAIT_NAVIGATION":   WaitNavigation, | ||||
| 		"XPATH":             XPath, | ||||
| 	} | ||||
| } | ||||
|  | ||||
|   | ||||
							
								
								
									
										31
									
								
								pkg/stdlib/html/xpath.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								pkg/stdlib/html/xpath.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | ||||
| package html | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
|  | ||||
| 	"github.com/MontFerret/ferret/pkg/drivers" | ||||
| 	"github.com/MontFerret/ferret/pkg/runtime/core" | ||||
| 	"github.com/MontFerret/ferret/pkg/runtime/values" | ||||
| ) | ||||
|  | ||||
| // XPath evaluates the XPath expression. | ||||
| // @param source (HTMLPage | HTMLDocument | HTMLElement) - Target HTML object. | ||||
| // @param expression (String) - XPath expression. | ||||
| // @returns (Value) - Returns result of a given XPath expression. | ||||
| func XPath(ctx context.Context, args ...core.Value) (core.Value, error) { | ||||
| 	err := core.ValidateArgs(args, 2, 2) | ||||
|  | ||||
| 	if err != nil { | ||||
| 		return values.None, err | ||||
| 	} | ||||
|  | ||||
| 	element, err := drivers.ToElement(args[0]) | ||||
|  | ||||
| 	if err != nil { | ||||
| 		return values.None, err | ||||
| 	} | ||||
|  | ||||
| 	expr := values.ToString(args[1]) | ||||
|  | ||||
| 	return element.XPath(ctx, expr) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user