元素目前不可见

时间:2015-06-29 03:56:10

标签: python selenium-webdriver

我使用selenium尝试登录MyBB以获取我所属的网站。我正在尝试制作一个喊盒机器人。 (是的,我有权这样做)我遇到的问题是我没有显示我尝试发送数据的元素。它可以找到但是说没有显示。代码显示已找到但未显示。有没有办法让它可见?

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


class shoutbox():
""" Class that will handle looging in to mybb and shout text """

    def __init__(self):
        self.driver = webdriver.Firefox()
        self.login_mybb()

    def login_mybb(self):
        url = r"http://www.rpgcreation.net/community/member.php?action=login"

        self.driver.get(url)

        try:
            WebDriverWait(self.driver, 15).until(EC.presence_of_element_located((By.NAME, "username")))
            print("found username")
            userName = self.driver.find_element(By.NAME, "username")
            if userName.is_displayed():
                print("username is displayed")
            else:
                print("username is not displayed")
        finally:
            self.driver.quit()


shoutbox()

1 个答案:

答案 0 :(得分:0)

你可以尝试这个xpath,

(//input[@name='username'])[2]

OR

//td/input[@name='username']