I'm making a youtube tool but when I run the code, it gives me this error.
CV = driver.find_element(By.XPATH('//*[@id="movie_player"]/div[5]/button')) TypeError: 'str' object is not callable
Here is the code.
driver = webdriver.Chrome()
driver.set_window_size(700,800)
U = self.lineEdit_3.text()
U = str(U)
text = "L "
text = str(text)
C = 0
V = self.spinBox_2.text()
V = int(V)
while (C < V):
driver.get(U)
time.sleep(5)
CV = driver.find_element(By.XPATH('//*[@id="movie_player"]/div[5]/button'))
CV.click()
C = C 1
CodePudding user response:
CV = driver.find_element(By.XPATH('//*[@id="movie_player"]/div[5]/button'))
This line causes the problem. The function WebDriver.find_element
has the following definition:
def find_element(self, by=By.ID, value=None) -> WebElement:
And the definition of By
:
class By(object):
"""
Set of supported locator strategies.
"""
ID = "id"
XPATH = "xpath"
LINK_TEXT = "link text"
PARTIAL_LINK_TEXT = "partial link text"
NAME = "name"
TAG_NAME = "tag name"
CLASS_NAME = "class name"
CSS_SELECTOR = "css selector"
So you should call
CV = driver.find_element(By.XPATH, '//*[@id="movie_player"]/div[5]/button')
By.* is of type str
and thus is not callable.
When using WebDriver.find_element
, you need to supply the content as a second argument.