Code Monkey home page Code Monkey logo

Comments (8)

arnoudbuzing avatar arnoudbuzing commented on May 28, 2024 1

That should be easy, I'm looking at it now.

Always interested in hearing how people use it.

from webtools.

arnoudbuzing avatar arnoudbuzing commented on May 28, 2024 1

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.

arnoudbuzing avatar arnoudbuzing commented on May 28, 2024

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.

wjxway avatar wjxway commented on May 28, 2024

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.

wjxway avatar wjxway commented on May 28, 2024

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.

wjxway avatar wjxway commented on May 28, 2024

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.

arnoudbuzing avatar arnoudbuzing commented on May 28, 2024

I understand what GetPageURL is useful for. But can you explain what Off/OnAlert is for?

from webtools.

wjxway avatar wjxway commented on May 28, 2024

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)

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.