Click here to Skip to main content
15,887,975 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 when I try to run the script:

TypeError: 'str' object not callable

Below is the test code I've written so far.

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


Here is a link to Stack Overflow where I have a snap of the command prompt: python - Automated Test Halt with TypeError: 'str' object not callable - Stack Overflow[^]

What I have tried:

I created the Tags class to pass the XPATH variables to find_element instead of passing them as strings directly, but that still didn't fix the problem, and adding an implicit wait before the click didn't help, either. I'd appreciate any advice.
Posted
Updated 18-Sep-21 11:20am

The format of your call to find_element is incorrect. See 4. Locating Elements — Selenium Python Bindings 2 documentation[^].
 
Share this answer
 
Fixed!

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


results = browser.find_element(By.XPATH, Tags.solPath)
 
Share this answer
 
Comments
PIEBALDconsult 13-Oct-21 9:34am    
Please don't try to answer your own question. If you have information to add, just add it to the question -- "Improve question".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900