0
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
path = "c:/users/admin/appdata/local/programs/python/python38-32/chromedriver.exe"
driver = webdriver.Chrome(path)


driver.get("https://donboscosdw.smartschool.be/login")

# Input fields
username = driver.find_element_by_name("login_form[_username]")
password = driver.find_element_by_name("login_form[_password]")
time.sleep(2)

username.clear()
password.clear()

# Login to website 
username.send_keys("...")
password.send_keys("...")
username.send_keys(Keys.RETURN)


class Notifications:
    ls = []

    # check for new messages 

    messages=driver.find_element_by_xpath('//*[@id="smscTopContainer"]/nav/div[4]/button/span').get_property('data_value')
    print(type(messages))

i want selenium to open my messages if i get a new one. But when i try to get the data_value . It returns None. But i want to retrieve whatever is in the data_value .

4
  • you're sure the value is in the data_value attribute. You can see it in the HTML Commented Jun 26, 2020 at 23:22
  • @MrBrN197 yes : whenever i receive a new message the value in data_value increase. ps. the value in data_value that i'm trying to get is a integer . Commented Jun 26, 2020 at 23:53
  • When you say It returns NoValue. I've never seen that in python... Can you tell me the exact Result. is It None Commented Jun 27, 2020 at 0:05
  • @MrBrN197 I am terrible sorry. I wrote the wrong thing , yes i meant to say None. Once again i am sorry . Commented Jun 27, 2020 at 0:22

2 Answers 2

1

You probably need to activate WebDriverWait and expected_conditions before getting the data.

With the following imports :

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

You can write :

email = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.xpath, "//*[@id='smscTopContainer']/nav/div[4]/button/span"))).get_attribute("value")
print (email)
Sign up to request clarification or add additional context in comments.

1 Comment

@bliboy While using Selenium, this approach within this answer should be the ideal way.
1
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
path = "c:/users/admin/appdata/local/programs/python/python38-32/chromedriver.exe"
driver = webdriver.Chrome(path)


driver.get("https://donboscosdw.smartschool.be/login")

# Input fields
username = driver.find_element_by_name("login_form[_username]")
password = driver.find_element_by_name("login_form[_password]")
time.sleep(2)

username.clear()
password.clear()

# Login to website
username.send_keys("...")
password.send_keys("...")
username.send_keys(Keys.RETURN)

# check for a new message 

class Notifications:
    email = WebDriverWait(driver, 20).until(EC.visibility_of_element_located(
        (By.XPATH, "//*[@id='smscTopContainer']/nav/div[4]/button/span"))).get_attribute('innerHTML')
    email = str(email)

    # if i have received new message open mail ,else print no message

    if email > str("0"):
        open_email = driver.find_element_by_xpath('//*[@id="smscTopContainer"]/nav/div[4]/button')
        open_email.send_keys(Keys.RETURN)
    else : 
        print("No New Messages")

I found a solution to the problem . You need to use .get_attribute('innerHTML'). which will return the value in the data_value and not a NoneType.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.