Code Monkey home page Code Monkey logo

webdriver's Introduction

webdriver

Nim webdriver for Chrome and Firefox

Usage

import asyncdispatch
import webdriver/[chromedriver, firefox]

proc test() {.async.} =
  let d = newFirefoxDriver()
  await d.startSession()
  await d.setUrl("https://nim-lang.org")
  let h1 = await d.getElementByTagName("h1")
  let text = await d.getElementText(h1)
  await d.close()
  echo text

waitFor test()

webdriver's People

Contributors

lihf8515 avatar yglukhov avatar inverimus avatar tormund avatar

Stargazers

Michael Krauter avatar  avatar  avatar  avatar Sultan Al Isaiee avatar pyroxenite avatar  avatar  avatar Bung avatar Jordan Callicoat avatar Nな人(N na hito) avatar  avatar  avatar jorjun avatar huaxk avatar Hitesh Jasani avatar

Watchers

James Cloos avatar  avatar  avatar huaxk avatar  avatar

webdriver's Issues

Can you write a usage tutorial?

I used your code and found no output, nor did I start the chrome browser. Here's my code:

import asyncdispatch
import chromedriver

type
  LocationStrategy* = enum
    CssSelector,
    LinkTextSelector,
    PartialLinkTextSelector,
    TagNameSelector,
    XPathSelector

proc toKeyword(strategy: LocationStrategy): string =
  case strategy
  of CssSelector: "css selector"
  of LinkTextSelector: "link text"
  of PartialLinkTextSelector: "partial link text"
  of TagNameSelector: "tag name"
  of XPathSelector: "xpath"

proc my() {.async.} =
  var driver = newChromeDriver()
  await driver.startSession()
  await driver.setUrl("http://www.ahszxhsd.com")
  var list = await driver.getElements(toKeyword(CssSelector),"navitem")
  echo(repr(list))
  await driver.close()

var r = my()

The sample code could not be executed due to an error.

I tried out the sample code in the README.
The following error occurred and the program could not be executed.

template/generic instantiation of `async` from here
Error: undeclared identifier: 'task'

So, I delete task method.
Then the following error occurred:

Additional info: "Requested command not found: \'\'. OS error:"
Exception type: [OSError]
Error: execution of an external program failed

I wrote the following simple code.
I was able to run it, but did not get the results I expected.
The source of the page was not output.

import asyncdispatch, strutils, json
import webdriver/chromedriver
  
proc main() {.async.} =
    var driver = newChromeDriver()
    var options = %*{
        "excludeSwitches": ["enable-automation"]
    }
    await driver.startSession(options)

    discard driver.setUrl("https://nnahito.com")

    echo repr(driver.getSource())

    await driver.close()

discard main()

my env

  • windows 10
  • Nim Compiler Version 1.2.0 [Windows: amd64]

I installed it with the following command.

> nimble install https://github.com/yglukhov/webdriver

Could you consider removing "firefox.nim"

Today, both firefox and chrome use the "W3C Webdriver" driver, while firefox proprietary drivers no longer seem to be supported, and "firefox.nim" doesn't work successfully. Could you consider removing "firefox.nim" and then changing "webdriver_base.nim" to a base class to remove "driver.nim "?

firefox.nim still has a flaw

firefox.nim still has a flaw: it's working well in the linux environment, but it failed in the win10 environment, and I couldn't find a reason why it went wrong in asyncokect's function connect.

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.