Python 为什么我总是得到;无法定位元素“0”;

Python 为什么我总是得到;无法定位元素“0”;,python,selenium,google-chrome,web-scraping,Python,Selenium,Google Chrome,Web Scraping,我是python新手,下面的代码给了我一个错误:“找不到元素:{”方法“:“xpath…”。我还尝试了按\ id查找\元素\以及按\名称查找\元素\但没有成功。我仍然收到一个错误,说找不到元素。这是因为元素在一个span类中吗 chrome_path = r"C:\DRIVERS\chromedriver.exe" driver = webdriver.Chrome(chrome_path) driver.get("""https://www.dynamiccommunities.com/wid

我是python新手,下面的代码给了我一个错误:“找不到元素:{”方法“:“xpath…”。我还尝试了按\ id查找\元素\以及按\名称查找\元素\但没有成功。我仍然收到一个错误,说找不到元素。这是因为元素在一个span类中吗

chrome_path = r"C:\DRIVERS\chromedriver.exe"
driver = webdriver.Chrome(chrome_path)
driver.get("""https://www.dynamiccommunities.com/widgets/generic?cobaltsrc=https%3A%2F%2Fdciug.dynamiccommunities.com%2FLogin.aspx%3FReturnUrl%3D%2FAuthentication%2FHigherLogicLogin.ashx%3FRedirectURL%3Dhttps%3a%2f%2fwww.dynamiccommunities.com%2fhome""")
driver.maximize_window()
driver.implicitly_wait(30)


driver.find_element_by_xpath("""//*[@id="FormContentPlaceHolder_LoginEditForm_UserName"]""").send_keys('test')
driver.find_element_by_xpath("""//*[@id="FormContentPlaceHolder_LoginEditForm_Password"]""").send_keys('***')
``



假设您的xpath是正确的,您可能还必须等待元素首先加载:
WebDriverWait(驱动程序,超时)。直到(EC.presence\u of_element\u located((By.xpath,xpath\u of_element)))
。如果这不起作用,请尝试按ID或类定位。也尝试了,但没有成功。您尝试过按ID定位吗?使用
FormContentPlaceHolder\u LoginEditForm\u用户名作为ID?是的,也尝试过。它只是超时。它在iframe中。