Can't find element to make if statement

marriedjane875

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:

enter image description here

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)

Naughty Ninja

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Selenium can't find element

From Dev

Javascript: can't find element

From Dev

Can't find element in frame

From Dev

Can't find element in frame

From Dev

Can't find an element by "querySelector"

From Dev

Can't find elements of element

From Dev

Can't find DOM element in jQuery

From Dev

IndexOf can't find last element in a List

From Dev

why can't find/parse this element in HTML?

From Dev

Can't find specific element in LinkedListNode

From Dev

Selenium IDE can't find an element

From Dev

Can't find an element Selenium Python

From Dev

jQuery: "this" can't find element generated by .html()

From Dev

PhotoSwipe Can't Find Element At Different Layout

From Dev

Can't find element by id using selenium

From Dev

Can't find element selenium python

From Dev

Protractor can't find element by binding $ctrl

From Dev

Can't find element by xpath with title as a variable

From Dev

can't find my element (selenium beginner)

From Dev

Can't find the boolean logic to make this work

From Dev

AngularJS Protractor element by.model can't find element?

From Dev

Polymer querySelector can't find custom polymer element in polymer element

From Dev

Polymer querySelector can't find custom polymer element in polymer element

From Dev

Can't find the id of parent element of clicked element using jquery

From Dev

Can't make a standard function forbidden using a preprocessor statement?

From Dev

I can't make event.key statement work

From Dev

Can't make a standard function forbidden using a preprocessor statement?

From Dev

Include statement: can't find SDL/SDL.h file

From Dev

SQL Select Statement off by one variable but can't find issue

Related Related

HotTag

Archive