Home > Software engineering >  TypeError: 'str' object is not callable (FIndElement)
TypeError: 'str' object is not callable (FIndElement)

Time:05-31

i try to find an Element by Text. If i want to click the Element i'll get the following Error:

TypeError: 'str' object is not callable

Any Idea how to fix that?

Here is my code

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from pynput.mouse import Button, Controller
from pynput.keyboard import Key, Controller as keyController
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
mouse = Controller()
keyboard = keyController()




driver = webdriver.Chrome('./chromedriver')
driver.implicitly_wait(10)
Ticket = False
link = 'https://www.fansale.de/fansale/tickets/hard-heavy/rammstein/526/12055317'
driver.get(link)
time.sleep(5)

#Cookies
print('The current pointer position is {0}'.format(
    mouse.position))
mouse.position = (1117, 824)
mouse.press(Button.left)
mouse.release(Button.left)

time.sleep(5)
driver.find_element(By.LINK_TEXT('Reihe 28')).click()

Website

CodePudding user response:

You are getting this error in the last row. This happens because you are trying to call By.LINK_TEXT filter that cannot be called. You need to separate your filter By.LINK_TEXT and the value 'Reihe 28' into two different parameters.

Replace your last string to this:

driver.find_element(by=By.LINK_TEXT, value='Reihe 28').click()

CodePudding user response:

driver.find_element(By.XPATH,"//span[contains(text(),'Reihe 20')]").click()

Grab the first span that contains that text.

  • Related