Skip to main content

Tool to control Selenium from command line

Project description

selenium-cmd

selenium-cmd is a small tool with which you can perform basic actions using a selenium webdriver object.

table of contents

  1. installation
  2. usage
  3. commands
    1. get
    2. exit
    3. click
    4. extract
    5. select
    6. write

installation

You can simply use

pip install selenium-cmd

usage

You can use the SeleniumCmd class wherever you want in your script.
You can do so by importing SeleniumCmd from selenium_cmd.

from selenium_cmd import SeleniumCmd

SeleniumCmd(your_driver).cmdloop()

If you do not provide your own driver, SeleniumCmd will instantiate one using Chrome() from selenium.webdriver.
This will open a prompt where you can type your commands looking like this:

selenium-cmd version 0.0.2
>

commands

get

With get you can navigate to different websites.
The following will navigate to http://example.com:

>get http://example.com

exit

The exit command will stop the execution of SeleniumCmd and continue with your regular program execution.

>exit

click

The click command will click the first element found specified by an XPath.
The following example will click the first link on http://example.com:

>get http://example.com
>click //a

extract

The extract command will print all elements matched by the provided XPath expression to your command line.
The following example will print all quotes from https://quotes.toscrape.com/:

>get https://quotes.toscrape.com/
>extract //span[@class="text"]/text()
1 The world as we have created it is a process of our thinking. It cannot be changed without changing our thinking.
2 It is our choices, Harry, that show what we truly are, far more than our abilities.
3 There are only two ways to live your life. One is as though nothing is a miracle. The other is as though everything is a miracle.
4 The person, be it gentleman or lady, who has not pleasure in a good novel, must be intolerably stupid.
5 Imperfection is beauty, madness is genius and it's better to be absolutely ridiculous than absolutely boring.
6 Try not to become a man of success. Rather become a man of value.
7 It is better to be hated for what you are than to be loved for what you are not.
8 I have not failed. I've just found 10,000 ways that won't work.
9 A woman is like a tea bag; you never know how strong it is until it's in hot water.
10 A day without sunshine is like, you know, night.

select

The syntax for the select command is: select xpath option
The select command will select an option by value from a select tag. The select tag needs to be specified by an XPath expression.
The following example will select the option "css" in the first select tag on https://www.w3docs.com/learn-html/html-select-tag.html:

>get https://www.w3docs.com/learn-html/html-select-tag.html
>select //select[@aria-label="Books"] css

write

The syntax for the write command is: write xpath text
The write command will write text to a text input field as specified. Text that contains whitespace must be enclosed in quotation marks.
The following example will write "Hello World!" in the search box of https://developer.mozilla.org/

>get https://developer.mozilla.org/
>write //input[@id="main-q"] "Hello World!"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

selenium-cmd-0.0.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

selenium_cmd-0.0.2-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file selenium-cmd-0.0.2.tar.gz.

File metadata

  • Download URL: selenium-cmd-0.0.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for selenium-cmd-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f9226a5347689d9a908e68b3305a51415914248a0a295f2f23b6b74cb4f1ae0a
MD5 df756b485249c66040b9a94164894139
BLAKE2b-256 90343d7f9b8dcaf80a44686b9a2ca8be8908db3e00b52ea5c7ba098d29c62d0d

See more details on using hashes here.

File details

Details for the file selenium_cmd-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: selenium_cmd-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for selenium_cmd-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5ffd7fd8de5cf3558a14c7a1f97d0712095de6f8cf4584cd4c092c98cb7e975c
MD5 4bf38788b086ef80d0a84e59c36c53f9
BLAKE2b-256 97c1bbb4e4b028d58b40767fba8166cfbf2386c4a747470bdedc5a57497681b4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page