Handling Multiple CSS Selectors

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Multiple Class</title>
</head>
<body>

<h1>Multiple Class</h1>

 <form name="domf1" method="post">

<div>
  <label for="Email" class="class-name1 class-name2"> Enter your email</label>
  <input type="email" class="class-name3 class-name1 class-name2 class-name4">
</div>

 </form>

</body>
</html>

 

import unittest
from time import sleep
from selenium import webdriver
from selenium.webdriver.common import desired_capabilities
from selenium.webdriver.support.wait import WebDriverWait
chrome_path ='/home/rahul/Documents/SeleniumPy/chromedriver'

class MyMultipleClassExample(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Chrome(chrome_path)
    def test_multipleclass(self):
        driver = self.driver
        driver.maximize_window()
        driver.get('http://localhost:63342/myFirstTest/multipleclass.html')

        driver.implicitly_wait(30)

        """
        This shows how to use multiple class names in the css selector
        """


        element1= driver.find_element_by_css_selector("label.class-name1")
        string1=str(element1.text)
        print(string1.strip())

        element2=driver.find_element_by_css_selector("input.class-name1.class-name3")
        element2.clear()
        element2.send_keys('ydv.rahul01@gmail.com')

        sleep(5)

        element3=driver.find_element_by_css_selector('input.class-name1.class-name2')
        element3.clear()
        element3.send_keys('tatha@gmail.com')

        sleep(5)


        element4= driver.find_element_by_css_selector("input[class='class-name3 class-name1 class-name2 class-name4']")
        element4.clear()
        element4.send_keys('lipzing@gmail.com')

        sleep(5)

        """
        Here we will use pattern matching for finding the css selector for this example.
        1. '^' symbol, represents the starting text in a string.
        2. '$' symbol represents the ending text in a string.
        3. '*' symbol represents contains text in a string.

        """

        element5=driver.find_element_by_css_selector("label[class^='class-name1']")
        print(element5.text)
        sleep(5)


        element6=driver.find_element_by_css_selector("label[class$='class-name2']")
        print(element6.text)
        sleep(5)


        element7=driver.find_element_by_css_selector("input[class*='class-name2']")
        element7.clear()
        element7.send_keys('narkanda@gmail.com')

        sleep(5)







    def tearDown(self):
        self.driver.quit()


if __name__ == '__main__':
    unittest.main()