1

日志向我抛出这个:

element.until(EC.presence_of_element_located(By.XPATH("//*[@id='menu-item-9145']/a'")))
TypeError: 'str' object is not callable

代码试验:

class Descaro:
    def __init__(self, driver):
        self.driver = driver

    def Descaro(self):
        time.sleep(3)
        self.driver.find_element_by_xpath("//*[@id='splashModal']/a[1]").click()
        print("deberia estar en la pagina de fondo")
        element = WebDriverWait(self.driver, 10)
        element.until(EC.presence_of_element_located(By.XPATH("//*[@id='menu-item-9145']/a'")))
        element.click()

我已经尝试过这个:

element.until(EC.presence_of_element_located(By.XPATH, '//*[@id="menu-item-9145"]/a''))) 

但也不起作用,因为:

__init__() takes 2 positional arguments but 3 were given
4

1 回答 1

1

你需要注意几件事:


解决方案

您需要诱导WebDriverWait并且element_to_be_clickable()您可以使用以下Locator Strategy

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='menu-item-9145']/a"))).click()

注意:您必须添加以下导入:

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

参考

您可以在以下位置找到一些相关的详细讨论:

于 2021-01-12T20:15:18.107 回答