1

Hi I have created a script to validate for the success or error message after filling the form, but it is throwing an assertion error for everything. Please help me out in fixing this error, Here is my script

import unittest
from selenium import webdriver
from selenium.webdriver.support.ui import Select
import time

class demo(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.driver = webdriver.Chrome()
        cls.driver.implicitly_wait(30)
        cls.driver.maximize_window()

        cls.driver.get("http://demoqa.com/")


    def test_Click(self):
        self.signup = self.driver.find_element_by_link_text('Registration').click()

    def test_Form(self):
        self.First_name = self.driver.find_element_by_xpath("//*[@id='name_3_firstname']").send_keys("Santosh")
        self.Last_name = self.driver.find_element_by_xpath("//*[@id='name_3_lastname']").send_keys("Kumar")
        self.Status = self.driver.find_element_by_xpath("//*[@id='pie_register']/li[2]/div/div/input[1]").click()
        self.Hobby = self.driver.find_element_by_xpath("//*[@id='pie_register']/li[3]/div/div[1]/input[2]").click()
        """self.Country = self.driver.find_element_by_id("dropdown_7")
        for option in self.Country.find_elements_by_tag_name('option'):
            if option.text == 'India':
                option.click()
                break"""
        self.Country = Select(self.driver.find_element_by_id("dropdown_7"))
        self.Country.select_by_value('India')
        self.month = Select(self.driver.find_element_by_xpath("//*[@id='mm_date_8']"))
        self.month.select_by_index(4)
        self.day = Select(self.driver.find_element_by_xpath("//*[@id='dd_date_8']"))
        self.day.select_by_index(11)
        self.year = Select(self.driver.find_element_by_xpath("//*[@id='yy_date_8']"))
        self.year.select_by_value('2014')
        self.phone = self.driver.find_element_by_xpath("//*[@id='phone_9']").send_keys("9738993098")
        self.username = self.driver.find_element_by_xpath("//*[@id='username']").send_keys("santu_tz6")
        self.email = self.driver.find_element_by_xpath("//*[@id='email_1']").send_keys("santu6@gmail.com")
        self.about = self.driver.find_element_by_xpath("//*[@id='description']").send_keys("Very much interested in Testing")
        self.password = self.driver.find_element_by_xpath("//*[@id='password_2']").send_keys("Secret97@1")
        self.confirm = self.driver.find_element_by_xpath("//*[@id='confirm_password_password_2']").send_keys("Secret97@1")
        self.submit = self.driver.find_element_by_xpath("//*[@id='pie_register']/li[14]/div/input").click()
        self.success = self.driver.find_element_by_xpath("//*[@id='post-49']/div/p").get_attribute('text')
        time.sleep(3)
        self.expected_text = "Error: Username already exists"
        self.assertEquals(self.success,self.expected_text)

    @classmethod
    def tearDownClass(cls):
    # close the browser window
        cls.driver.quit()
    if __name__ == '__main__':
         unittest.main()
0

What's the value in the self.succcess?

If this is NULL or "", either your locator is wrong or the error is not displayed at the time of findElement. In the second case, you probably need to wait for the error message is visible before querying its text.

  • Hi Joa, I have pasted my complete code, can you please help me in fixing this error.. – Santosh May 13 '17 at 21:41
0

To fetch the success or failure message need to replace get_attribute('text') to get_attribute('textContent'). Simple, but effective.

  • Santosh, even though it's your own answer, you should accept it if that is what indeed solved your problem. – corsiKa May 15 '17 at 21:38
  • @BharatMane But he found the problem and posted his solution. This IS the answer. He was just being polite which is bad on Stack Exchange in a weird but reasonable way. – corsiKa May 15 '17 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.