Tell me how you can register a simple search of incorrect logins / passwords to perform negative test cases in the list.

  1. There is a certain list that contains usernames / passwords with invalid characters that we will check:

    list = ["log in", "lögin", "login%"] 

    etc. You can, of course, import from a file, but the list is simpler.

  2. We have the Login field, where we will first insert the first value from the list:

     driver.find_element_by_id("Login").send_keys(list[0]) 
  3. Press the OK button:

     driver.find_element_by_id("OK_button").click() 

    After that, the expected result is that the form will display a message: "The Login field has invalid format." - i.e. everything goes according to plan and we are not allowed to create an account with invalid characters.

  4. I understand that to draw up a condition, you can push away from this message appearing on the page:

     driver.find_element_by_link_text("The Login field has invalid format.") 

After that we have to erase the login in the Login field and substitute the next in the list:

 driver.find_element_by_id("Login").clear() driver.find_element_by_id("Login").send_keys(list[1]) driver.find_element_by_id("OK_button").click() 

Tell me, please, how to do this process with fewer lines of code.

Writing three lines for each value from the list is not a very productive solution, especially if there can be up to a hundred elements in the list.

    1 answer 1

    You can make all the function, and then use the list inclusion:

     def check_login(login): driver.find_element_by_id("Login").send_keys(login) driver.find_element_by_id("OK_button").click() driver.find_element_by_link_text("The Login field has invalid format.") driver.find_element_by_id("Login").clear() incorrect_logins = ["log in", "lögin", "login%"] # не стоит использовать list в качестве имени переменной так как есть встроенная функция list. [check_login(incorrect_login) for incorrect_login in incorrect_logins] 
    • Thank you so much! It all worked! I have not yet come to this in studying Python ... - dmitry