0

tring this codebut throwing an attribute error
driver: WebDriver = webdriver.Chrome("C:\Drivers\chromedriver_win32\chromedriver.exe")

driver.get("https://opensource-demo.orangehrmlive.com/")
driver.find_element_by_name("txtUsername").send_keys("Admin")
driver.find_element_by_id("txtPassword").send_keys("admin123")
driver.find_element_by_id("btnLogin").click()

act_title=driver.title
exp_title="OrangeHRM"

if act_title==exp_title:
    print("Login test pass")
else:
    print("Login test fail")

driver.close()
Prophet
  • 32,350
  • 22
  • 54
  • 79

4 Answers4

0

Just do this:

driver = webdriver.Chrome('C:\Drivers\chromedriver_win32\chromedriver.exe')

There is no need to declare WebDriver as driver.

Tal Angel
  • 1,301
  • 3
  • 29
  • 63
0

The name attribute for the User Name element is username.

The name attribute for the Password element is password.

Otherwise, you can use other locators like xpath like -

//input[@placeholder='Username']
indayush
  • 55
  • 2
  • 9
0

All the methods like find_element_by_name, find_element_by_xpath, find_element_by_id etc. are deprecated now.
You should use find_element(By. instead.
So, your code can be as following:

driver.get("https://opensource-demo.orangehrmlive.com/")
driver.find_element(By.NAME, "txtUsername").send_keys("Admin")
driver.find_element(By.ID, "txtPassword").send_keys("admin123")
driver.find_element(By.ID, "btnLogin").click()

act_title=driver.title
exp_title="OrangeHRM"

if act_title==exp_title:
    print("Login test pass")
else:
    print("Login test fail")

driver.close()

Also, you should add delays in the above code. WebDriverWait should be used for that

Prophet
  • 32,350
  • 22
  • 54
  • 79
0

you are accessing wrong attribute that is not on the webpage or maybe you have written name of attributes and there value try CSS selector or XPath Example: driver.findElement(By.xpath("//TagName[@attribute='value']")); or driver.findElement(By.cssSelector(""));