Comments (8)
That should be easy, I'm looking at it now.
Always interested in hearing how people use it.
from webtools.
Yes: The WebDriver protocol provides the basics (launching a browser, opening web pages, navigating pages, clicking and typing, etc.). But there are many common and useful things one might want to to, so building higher level Wolfram Language functions based on WebDriver functions + Javascript is a good direction to extend this package.
from webtools.
Quick solution, use JavascriptExecute
(change 'id' to what you need):
JavascriptExecute["return document.getElementById('id').innerHTML;"]
Or, as a Wolfram Language function:
GetHtmlForId[id_String] := JavascriptExecute[
"return document.getElementById('" <> id <> "').innerHTML;"]
from webtools.
Thanks a lot! JavascriptExecute
is really powerful! BTW, I checked your source code, it seems that most of the existing functions like ClickElement
are actually done by calling JavascriptExecute
, am I right?
from webtools.
Some additional methods for getting HTMLs:
Options[GetHTML]={"Selection"->"outer"};
GetHtml[Selector[sel_String],OptionsPattern[]] := JavascriptExecute[ "return document.querySelector('" <> sel <> "')."<>OptionValue["Selection"]<>"HTML;"]
GetHTML[XPath[xp_String],OptionsPattern[]] := JavascriptExecute["document.evaluate('"<>xp<>"', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue."<>OptionValue["Selection"]<>"HTML;"]
and your GetHtmlForId:
GetHtml[Id[id_String],OptionsPattern[]] := JavascriptExecute["return document.getElementById('" <> id <> "')."<>OptionValue["Selection"]<>"HTML;"]
from webtools.
Also, here's a few frequently used functions when I'm using WebUnit:
GetPageURL[]:=JavascriptExecute["return window.location.href;"]
OffAlert[]:=JavascriptExecute[ "window.alert=function(){return 1}; window.confirm=function(){return 1}; window.prompt=function(){return 1};"]
from webtools.
I understand what GetPageURL
is useful for. But can you explain what Off
/OnAlert
is for?
from webtools.
Errr, I modified the code a bit, It seems that the old version didn't work out.....
OffAlert is used to turn off all alerts or confirmation windows created by alert(), confirm() and prompt(). Once these alerts are on, it's impossible(?) to control the web page anymore without a human clicking "confirm" button and turn the alert off, which is annoying......
from webtools.
Related Issues (12)
- Import Source HOT 2
- Unable to get CaptureWebPage[] function to work HOT 14
- WebUnit crash after opening certain webpages HOT 3
- Download Image using WebUnit HOT 3
- A tricky solution to Chinese directory names HOT 3
- Suggestion: verify connection to browser after InstallWebUnit[] HOT 5
- StartWebSession not working? HOT 3
- Misspelling in `QueryMethod` and `QueryValue`?
- How to catch the full cookies?
- EdgeDriver's high OS dependency HOT 10
- Starting Chrome using StartExternalSession with SessionOptions
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 webtools.