Home > OS >  Automated Test Halt with TypeError: 'str' object not callable
Automated Test Halt with TypeError: 'str' object not callable

Time:09-22

I'm writing an automated UI test for a simple Web application which uses Angular 10 on the front end. The bot needs to click a button, which produces a table on the screen, and then it looks for a specific entry on the table. I keep getting the following error:

enter image description here

Included below is a sample of the test:

import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver import Firefox
from selenium.webdriver.common.keys import Keys

class Tags:

  starSysButton = '//li[button][1]'
  solPath = f"//td[contains(text(),'Sol')]"

@pytest.fixture
def browser():
  driver = Firefox()
  driver.implicitly_wait(10)
  yield driver
  driver.quit()

def test_basic_landing_page(browser):
  URL = 'http://localhost:4200'
  
  browser.get(URL)

  starElement = browser.find_element(By.XPATH(Tags.starSysButton))
  starElement.click()

  results = browser.find_element(By.XPATH(Tags.solPath))
  if results:
    assert results

I'm not sure what the problem is. I originally passed the XPATH strings directly in the call to find_element but got the same error, so I created the class Tags, and passed them that way. Still the same problem.

CodePudding user response:

Selenium documentation, Section 4

starElement = browser.find_element(By.XPATH, Tags.starSysButton)

results = browser.find_element(By.XPATH, Tags.solPath)

  • Related