Reputation: 21
I am pretty new to this and I've been stuck for about 2 days. I will try my best to explain my issue.
This is the element i am trying to find:
<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>
I need it to find either where it says clear or where it says Password Incorrect. When the password is incorrect material-icons will say clear and when it's correct it says done. div style says successful! when correct.
This is my code so far:
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)
When i print(result.text) it says "store" every time. When I was trying some other things it was saying "center_circle". I'm trying to make print(result.text) display either clear or Password Incorrect. I think I'm not finding the element correctly but I'm not sure anymore.
Upvotes: 1
Views: 50
Reputation: 33384
After clicking on the account button.Induce WebDriverWait
() and visibility_of_element_located
() and following 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)
Upvotes: 1