无法使用xpath和Webdriver打印特定数据

时间:2018-08-24 07:40:39

标签: python xpath webdriver

无法使用xpath和webdriver打印特定数据

from selenium import webdriver

driver = webdriver.Firefox()
driver.get("https://datatables.net/")
print driver.findtext('.//*[@id="example"]/tbody/tr[1]/td[1]')

预期结果:

Airi Satou

1 个答案:

答案 0 :(得分:1)

尝试此操作以获得所需的输出:

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

print(wait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//table[@id="example"]//td'))).text)