![](/img/trans.png)
[英]How to get text from tooltip with no attributes using Selenium Webdriver with Python?
[英]How to get element(text) from a table using Selenium WebDriver with Python
嘗試使用 XPATH 從表中獲取元素(文本)然后打印,但出現以下錯誤:
NoSuchElementException:消息:沒有這樣的元素:無法找到元素。
我已經等了一段時間,但得到了同樣的錯誤。 我怎樣才能得到文本?
我使用了以下代碼:
account = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="ctl00_lc_ucLeftMenu_li_1_4"]/a[2]')))
account.click()
time.sleep(3)
portfolio = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="ctl00_lc_ucLeftMenu_leaf_2_35"]')))
portfolio.click()
time.sleep(3)
sold = driver.find_element_by_xpath('//*[@id="37ef7b7a-3a62-4d56-a479-29c99031de7e"]/table/tbody/tr[8]/td[5]')
print('The amount is: {}'.format(sold.text))
sold1 = float(sold.text)
請參閱附件 - 以獲取突出顯示的文本。
要獲得該特定文本,xpath 不是正確的。 相反,我使用了以下一個:
//table/tbody/tr[8]/td[10]
完整的代碼如下所示:
account = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH, '//*
[@id="ctl00_lc_ucLeftMenu_li_1_4"]/a[2]')))
account.click()
time.sleep(3)
portfolio = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH, '//*
[@id="ctl00_lc_ucLeftMenu_leaf_2_35"]')))
portfolio.click()
time.sleep(3)
sold = driver.find_element_by_xpath('//table/tbody/tr[8]/td[5]')
print('The amount is: {}'.format(sold.text))
sold1 = float(sold.text)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.