I have a very simple Python/Selenium web-scraping script, as follows:
from re import L
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
cService = webdriver.ChromeService(executable_path="C:\Users\Frank\Documents\Visual Studio 2022\Projects\IV3_WebsiteAutomation\chromedriver.exe")
driver = webdriver.Chrome(service = cService)
driver.get("https://app.iv3.us/login")
print(driver.title)
search_bar = driver.find_element("name", "userName")
search_bar.send_keys("[email protected]")
search_bar = driver.find_element("name", "password")
search_bar.send_keys("xxxxxxxxxxxxxxx")
search_bar.send_keys(Keys.RETURN)
# res = driver.find_element(By.XPATH(".//a[contains(@href,'View Active')]"))
# res = driver.find_element(By.XPATH("//a[contains(@href,'View Active')]"))
XXX = driver.find_element(By.XPATH("//div[./h4[text()='Moved from Registered Address']]//a[text()='View Active']"))
driver.close()
When run, the ‘XXX = driver.find_element…’ line produces the dreaded ‘str’ object is not callable error.
Googling the error has led me to numerous posts describing how this error is caused by attempting to use a Python reserved word for a variable, but I can’t see how that could be happening in my script; I even went so far as to change the ‘res’ variable name to ‘XXX’, but this didn’t change anything.
Could it be that this line:
from selenium.webdriver.common.by import By
and its subsequent use in the last line of the script is causing the problem? I got this usage from the Selenium ‘Locating Elements’ tutorial , so I would be amazed if it was the issue, but….
TIA,
Frank