Why Automation?
To add advanced features to our Assistant, we use automation, which can be deployed to many different websites, so we're using Spotify as an example; you can use other websites for testing. The video shows an example of Spotify automation. Similar concepts are used in all sorts of automation. Spotify API was intentionally not used for automation because I wanted to use a concept instead. With the help of APIs, you can also implement this! Explore and learn!
Remember to try to experiment with other platforms, we will see much more automation in the future videos, So stay tuned till then.
What is Selenium Automation?
We can say that Selenium is an open source testing framework that is required for automation or that it is one of a number of automation tools/frameworks for automating applications. The test cases are run multiple times across browsers
Which is better Xpath OR CSS_SELECTOR?
Download Chrome driver :
By Using Xpath
You can use Inspect button or the Extension to find the Xpath of the element
Chrome-extensions :
- import config #config.py has username and password
- from selenium import webdriver
- from time import sleep
- from selenium.webdriver.common.by import By
- options = webdriver.ChromeOptions()
- options.headless = True # if false all the stuff will load in backend
- driver = webdriver.Chrome('') # driver path cheak your current browser first than download respectively >>
- # chrome://settings/help
- url = 'https://accounts.spotify.com/en/login?continue=https%3A%2F%2Fopen.spotify.com%2F'
- def login(Email, Password):
- driver.get(url)
- driver.maximize_window()
- # WITH XPATH
- driver.find_element(By.XPATH, '//*[@id="login-username"]').send_keys(Email)
- driver.find_element(By.XPATH, '//*[@id="login-password"]').send_keys(Password)
- driver.find_element(By.XPATH, '//*[@id="login-button"]/div[1]/p').click()
- sleep(2) # we wait for page to load /-OR else we see !ERROR(only some times)
- login(config.username, config.password)
By Using CSS_SELECTOR
You can use Inspect button or the Extension to find the CSS_SELECTOR of the element
Chrome-extensions :
- import config #config.py has username and password
- from selenium import webdriver
- from time import sleep
- from selenium.webdriver.common.by import By
- options = webdriver.ChromeOptions()
- options.headless = True # if false all the stuff will load in backend
- driver = webdriver.Chrome('') # driver path cheak your current browser first than download respectively >>
- # chrome://settings/help
- url = 'https://accounts.spotify.com/en/login?continue=https%3A%2F%2Fopen.spotify.com%2F'
- def login(Email, Password):
- driver.get(url)
- driver.maximize_window()
- # WITH XPATH
- driver.find_element(By.CSS_SELECTOR, "#login-username").send_keys(Email)
- driver.find_element(By.CSS_SELECTOR, "#login-password").send_keys(Password)
- driver.find_element(By.CSS_SELECTOR, "button[id='login-button'] div:nth-child(1)").click()
- sleep(2) # we wait for page to load /-OR else we see !ERROR(only some times)
- login(config.username, config.password)