Can't find certain element exists I would like to put into if statement: (EDIT)
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
import sys
import smtplib
email = "[email protected]"
pswd = "EiEHzciBT668"
driver = webdriver.Chrome()
actions = ActionChains(driver)
driver.get("http://www.tumblr.com/login")
driver.find_element_by_id("signup_email").send_keys(email)
driver.find_element_by_id("signup_password").send_keys(pswd)
driver.find_element_by_id("signup_forms_submit").click()
#wait = WebDriverWait(driver, 5)
time.sleep(5)
iframe = driver.find_element_by_tag_name("iframe")
driver.switch_to_frame(iframe)
terminated = driver.find_element_by_xpath("//div[contains(@class, 'center_item')]/h1")
#terminated = driver.find_element_by_xpath("//*[@id='account_actions_suspended']")
if terminated:
driver.close()
after the login fails I would like for the page to determine if the account is suspended. The html is below:
I figured if I can find this element, I should be able to make an if statement.
This is my error:(EDIT)
Traceback (most recent call last): File "tumblrtest.py", line 32, in <module> terminated = driver.find_element_by_xpath("//div[contains(@class, 'center_item')]/h1") File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 253, in find_element_by_xpath return self.find_element(by=By.XPATH, value=xpath) File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 707, in find_element {'using': by, 'value': value})['value'] File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 196, in execute self.error_handler.check_response(response) File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 181, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element (Session info: chrome=44.0.2403.155) (Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Mac OS X 10.7.5 x86_64)
Try this:
var iframe = driver.find_element_by_tag_name("iframe")
driver.switch().frame(iframe)
terminated = driver.find_element_by_Xpath("//div[contains(@class, 'center_item')]/h1")
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments