我能够使用Python和Selenium找到网页的元素吗?如果特定文本存在于同一个元素中,我是否可以找到。
以下是我的代码:
import datetime, time
from selenium import webdriver
from pathlib import Path
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(executable_path=r'C:\chromedriver_win32\chromedriver.exe', chrome_options=options)
driver.implicitly_wait(30)
today = time.strftime("%d/%m/%Y")
print(today)
driver.get("http://mylink.com")
uname = driver.find_element_by_name("UserName")
pwd = driver.find_element_by_name("Password")
uname.send_keys("@.com")
pwd.send_keys("pwd")
driver.find_element_by_xpath('//*[@id="submitButton"]').click()
time.sleep(30)
element=driver.find_element_by_xpath('//*[@id="block-system-main"]/div/div/div/div[3]/div/div/div[2]/div/div[2]/table/tbody/tr[1]/td[6]/span/font/font')
Belos是我得到的错误。
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="block-system-main"]/div/div/div/div[3]/div/div/div[2]/div/div[2]/table/tbody/tr[1]/td[6]/span/font/font"}
答案 0 :(得分:0)
要等待元素中存在特定文本,您可以使用以下解决方案:
WebDriverWait(driver,10).until(EC.visibility_of(driver.find_element_by_xpath("//nodeTag[contains(.,'text_to_be_present')]")))