A Python package that uses Selenium to enable for automating tests for web applications.
Get Google Chrome’s driver from https://sites.google.com/a/chromium.org/chromedriver/downloads
Put the web driver executable in any folder and add that folder to $PATH
Run pip install pyselenium
After successfully going through the setup instructions, you can start programming your tests like so:
from pyselenium.test_metadata import Test
from pyselenium.test_steps import *
from pyselenium.test_runner import *
test = Test('My test')
test.add_step(Navigate('http://www.google.com'))
test.add_step(TypeText(css_path='#lst-ib', hint='Google search bar', text='Automating a Google search'))
test.add_step(SendEnter())
test_runner = TestRunner(test)
test_result = test_runner.run_test()
print(test_result)
#Used to import the package & set up a driver object
#PhantomJS exe should be in program/code directory.
from selenium import webdriver
driver = webdriver.PhantomJS()
url = 'http://flipkart.com'
driver.get(url)
print driver.title
[OP]: Online Shopping Site for Mobiles, Fashion, Books, Electronics, Home Appliances and More
#Chrome exe should be in program/code directory.
from selenium import webdriver
driver = webdriver.Chrome()
url = 'http://flipkart.com'
driver.get(url)
print driver.title
[OP]: Online Shopping Site for Mobiles, Fashion, Books, Electronics, Home Appliances and More
from selenium import webdriver
driver = webdriver.PhantomJS()
url = "http://flipkart.com"
driver.get(url)
driver.save_screenshot('HomePage.png')
from selenium import webdriver
from bs4 import BeautifulSoup
driver = webdriver.Chrome()
url = "https://www.flipkart.com/redmi-note-6-pro-blue-64-gb/p/itmfayzxgzxwfvx6?pid=MOBFAJB4RSWTEYJJ"
driver.get(url)
soup = BeautifulSoup(driver.page_source)
product_name = soup.select('._35KyD6')[0].text
print product_name
driver.close()
[OP]: Redmi Note 6 Pro (Blue, 64 GB) (4 GB RAM)
from selenium import webdriver
from bs4 import BeautifulSoup
driver = webdriver.Chrome()
url = "https://www.flipkart.com/redmi-note-6-pro-blue-64-gb/p/itmfayzxgzxwfvx6?pid=MOBFAJB4RSWTEYJJ"
driver.get(url)
zipcode = driver.find_element_by_class_name('_3X4tVa')
zipcode.send_keys('641035')
driver.find_element_by_class_name('_2aK_gu').click()
soup = BeautifulSoup(driver.page_source)
stock = soup.select('._13J5uS')
if stock:
stock = stock[0].text
print stock
driver.close()
[OP]: Currently out of stock in this area.