找不到正确的元素文本



我对此很陌生,我已经卡了大约 2 天。我会尽力解释我的问题。

这是我试图找到的元素:

<div id="popupContent" style="display: block; width: 300px;">
<div style="width:100%;text-align:center">
<div>
<i class="material-icons" style="font-size:80px;color:#e33b3b">clear</i>
</div>
<div style="font-size:20px;color:rgba(255,255,255,0.5)">Password Incorrect</div>
</div>
</div>

我需要它找到它说清楚的地方或它说密码不正确的地方。当密码不正确时,材料图标会说清楚,当密码正确时,它说完成。div 风格说成功!正确时。

这是我到目前为止的代码:

import time
import sys
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException, ElementNotInteractableException, 
StaleElementReferenceException, WebDriverException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36'
options = webdriver.ChromeOptions()
options.add_experimental_option("useAutomationExtension", False)
options.add_argument("--disable-extensions")
#options.add_argument('headless')
options.add_argument(f'user-agent={user_agent}')
options.add_argument('log-level=2')
options.add_argument("--mute-audio")
options.add_argument("window-size=800,600")
driver = webdriver.Chrome(chrome_options=options)

def get_result(user, passw):
driver.get("website")
time.sleep(5)
python_button = driver.find_element_by_id('profileLogin')
python_button.click()
password = WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.ID, "accName")))
password.send_keys(passw)
username = WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.ID, "accPass")))
print(str(word_counter) + " " + passw)
username.send_keys(user)
login = driver.find_element_by_class_name('accountButton')
login.click()
result = driver.find_element_by_css_selector('i.material-icons')
time.sleep(2)
print(result.text)

当我打印(result.text(时,它每次都说"存储"。当我尝试其他一些事情时,它说"center_circle"。我正在尝试使打印(结果.文本(显示清晰或密码不正确。我想我没有正确找到元素,但我不再确定。

点击帐户按钮后。诱导WebDriverWait(( 和visibility_of_element_located(( 并遵循 xpath。

print(WebDriverWait(driver,15).until(EC.visibility_of_element_located((By.XPATH,"//div[@id='popupContent']//i[@class='material-icons']"))).text)
print(WebDriverWait(driver,15).until(EC.visibility_of_element_located((By.XPATH,"//div[@id='popupContent']//i[@class='material-icons']/following::div[1]"))).text)

相关内容

  • 没有找到相关文章

最新更新