1

Hello so I am trying to login and then scan the html for a form error. I am using the selenium library. heres the html code I am trying to find:

<div class="_3_2jD" id="form_error"><p>Please check the code we sent you and try again.</p></div>

this is my code I am using to try and find it:

       if "form_error" in self.chrome_browser.page_source:
                print("trying again" + random_code)

any suggestions :D

2 Answers 2

1

The easiest way is to use find_element_by_id() or find_element_by_xpath()

from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("http://www.your_page.com")
driver.maximize_window()
time.sleep(5)
try:
    inputElement = driver.find_element_by_id("form_error")  #or  driver.find_element_by_xpath("//div[contains(@id,'form_error')]")
except NoSuchElementException:
    return False

https://stackoverflow.com/a/9587938/12451425 https://www.techbeamers.com/locate-elements-selenium-python/#locate-element-by-id

Sign up to request clarification or add additional context in comments.

Comments

0

You can check the element len, utilize .find_elements_*:

if(len(self.chrome_browser.find_elements_by_id('form_error'))>0):
    print("trying again" + random_code)

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.