Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何使用python selenium检查元素中是否存在文本?_Python 3.x_Selenium_Selenium Webdriver_Webdriver_Webdriverwait - Fatal编程技术网

Python 3.x 如何使用python selenium检查元素中是否存在文本?

Python 3.x 如何使用python selenium检查元素中是否存在文本?,python-3.x,selenium,selenium-webdriver,webdriver,webdriverwait,Python 3.x,Selenium,Selenium Webdriver,Webdriver,Webdriverwait,我能够使用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\chromed

我能够使用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')
贝洛斯是我得到的错误

 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"}

要等待元素中存在特定文本,可以使用以下解决方案:

WebDriverWait(driver,10).until(EC.visibility_of(driver.find_element_by_xpath("//nodeTag[contains(.,'text_to_be_present')]")))

共享您当前的代码、HTML、所需的输出…需要OP提供更多的输入、共享HTML以及您迄今为止所做的尝试吗?请参阅:so的期望是,用户提出问题时不仅要进行研究以回答他们自己的问题,还要共享研究、代码尝试和结果。这表明你花了时间来帮助自己,它使我们避免重复显而易见的答案,最重要的是,它帮助你得到一个更具体和相关的答案!另请参见:为什么不在元素中使用EC.text_to_be_present_?见文件:。谢谢杰夫。。但是,即使我无法找到元素,这是否有效。