我有以下三个按钮,我不知道如何抓取其中的文本(例如离群值)。我尝试了 browser.find_element_by_link_text("Outliers").click()
,但出现“无法定位元素”错误。我该怎么做?
最佳答案
参见:find_element_by_* commands are deprecated in selenium
在较新版本的 selenium 中尝试:
from selenium.webdriver.common.by import By
browser.find_element(By.XPATH, '//button[text()="Outliers"]')
旧版本的 Selenium :
browser.find_element_by_xpath('//button[text()="Outliers"]')
为了更新所有旧版本,我在这里找到了一个漂亮的正则表达式,然后只需修复导入:
关于python - 如何通过其内部文本(Python)找到带有 Selenium 的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49906237/