Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You mean Selenium WebDriver? Huh....</p> <p><strong>Prerequisite</strong>: Install Python based on your OS</p> <p>Install with following command </p> <pre><code>pip install -U selenium </code></pre> <p>And use this module in your code </p> <pre><code>from selenium import webdriver </code></pre> <p>You can also use many of the following as required </p> <pre><code>from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select from selenium.common.exceptions import NoSuchElementException </code></pre> <h2>Here is an updated answer</h2> <p>I would recommend you to run script without IDE... Here is my approach</p> <ol> <li>USE IDE to find xpath of object / element</li> <li>And use find_element_by_xpath().click() </li> </ol> <p>An example below shows login page automation </p> <pre><code>#ScriptName : Login.py #--------------------- from selenium import webdriver #Following are optional required from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select from selenium.common.exceptions import NoSuchElementException baseurl = "http://www.mywebsite.com/login.php" username = "admin" password = "admin" xpaths = { 'usernameTxtBox' : "//input[@name='username']", 'passwordTxtBox' : "//input[@name='password']", 'submitButton' : "//input[@name='login']" } mydriver = webdriver.Firefox() mydriver.get(baseurl) mydriver.maximize_window() #Clear Username TextBox if already allowed "Remember Me" mydriver.find_element_by_xpath(xpaths['usernameTxtBox']).clear() #Write Username in Username TextBox mydriver.find_element_by_xpath(xpaths['usernameTxtBox']).send_keys(username) #Clear Password TextBox if already allowed "Remember Me" mydriver.find_element_by_xpath(xpaths['passwordTxtBox']).clear() #Write Password in password TextBox mydriver.find_element_by_xpath(xpaths['passwordTxtBox']).send_keys(password) #Click Login button mydriver.find_element_by_xpath(xpaths['submitButton']).click() </code></pre> <p>There is an another way that you can find xpath of any object -</p> <ol> <li>Install Firebug and Firepath addons in firefox</li> <li>Open URL in Firefox</li> <li>Press F12 to open Firepath developer instance </li> <li>Select Firepath in below browser pane and chose select by "xpath" </li> <li>Move cursor of the mouse to element on webpage</li> <li>in the xpath textbox you will get xpath of an object/element.</li> <li>Copy Paste xpath to the script.</li> </ol> <p>Run script -</p> <pre><code>python Login.py </code></pre> <p>You can also use a CSS selector instead of xpath. CSS selectors are slightly faster than xpath in most cases, and are usually preferred over xpath (if there isn't an ID attribute on the elements you're interacting with).</p> <p>Firepath can also capture the object's locator as a CSS selector if you move your cursor to the object. You'll have to update your code to use the equivalent find by CSS selector method instead -</p> <pre><code>find_element_by_css_selector(css_selector) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload