Skip to content Skip to sidebar Skip to footer

How To Get Text Generated By Js In Selenium?

I am trying to get the text 'Incorrect Credentials' which is placed on page (js) when the user enters an incorrect user name and password... login_button.click() self.driver.implic

Solution 1:

You can use an explicit waiting (it works every time in my case):

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

WebDriverWait(self.driver, 10).until(
    EC.presence_of_element_located((By.XPATH, '//*[@id="toast-container"]/div/div[1][@class="ng-binding toast-title"]'))
)

Solution 2:

I'm unable to comment on rts's question

@@erthalion How to get the xpath of toaster messages.

because I don't have enough reputation points. The answer is:

Right before clicking the login button do this:

  1. Open DevTools -> Elements tab

  2. Create a breakpoint at the body tag, or even better: the parent tag of the element you are trying to find, select break on subtree modifications

  3. Press F8

  4. Click "Login"

  5. Then step through until the toastr is in view

  6. Inspect the toastr and retrieve xpath/cssSelector

Like so I can get enough reputation points so I can actually comment on things :D

Post a Comment for "How To Get Text Generated By Js In Selenium?"