弹出窗口中的登录脚本。没有这样的元素

时间:2019-03-05 13:11:21

标签: python selenium selenium-webdriver

我正在尝试获取登录脚本以选择要输入的用户名,以输入我的用户名。弹出窗口完成后,将再有一个询问密码。我是python和Web界面的新手,因此无法确定需要选择网站的哪个元素才能使其正常工作。这是我到目前为止的代码。

 db.Database.ExecuteSqlCommand("CALL GenarateTable(@tablename)", new MySqlParameter("@tablename", tenantDetail.tablename));

网站正在打开,并且弹出窗口正在启动,但是没有输入任何文本。这就是我得到的结果:

import selenium
from selenium import webdriver

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait as wait

DynamoForum = webdriver.Chrome()
DynamoForum.get("https://forum.dynamobim.com/")

login = DynamoForum.find_element_by_class_name("header-buttons").click()

#DynamoForum.switch_to_frame(DynamoForum.find_element_by_
#wait(DynamoForum,10).until(EC.frame_to_be_available_and_switch_to_it(
DynamoForum.find_element_by_xpath("//title[1]")))


wait(DynamoForum,10).until(EC.frame_to_be_available_and_switch_to_it(
DynamoForum.find_element_by_xpath(
"//iframe[@id='destination_publishing_iframe_autodesk_0']")))

DynamoForum.find_element_by_id("userName").send_heys("xxx")

2 个答案:

答案 0 :(得分:0)

您需要切换到iframe。

例如

iframe = driver.find_element_by_id('destination_publishing_iframe_autodesk_0')
driver.switch_to.frame(iframe)
driver.find_element_by_name('userName').send_keys('xxx')

在此处查看switch_to函数:https://selenium-python.readthedocs.io/api.html?highlight=iframe

供参考:

python selenium cant find iframe xpath

https://seleniumwithjavapython.wordpress.com/selenium-with-python/intermediate-topics/handling-iframes-in-a-webpage/

答案 1 :(得分:0)

基本上,当您单击login按钮时,您将移至另一个window,并且要访问新window中的元素,您需要从parent窗口中进行切换可以尝试以下代码。

    from selenium import webdriver
        DynamoForum = webdriver.Chrome()
        DynamoForum.get("https://forum.dynamobim.com/")
        Parent_window = DynamoForum.window_handles[0]
        login = DynamoForum.find_element_by_class_name("header-buttons").click()
        window_child= DynamoForum.window_handles[1]
        DynamoForum.switch_to.window(window_child)
        DynamoForum.find_element_by_id("userName").send_keys("xyz@gmail.com")
        DynamoForum.find_element_by_id("verify_user_btn").click()
        wait=WebDriverWait(DynamoForum,20)

     wait.until(EC.visibility_of_element_located((By.ID,"password"))).send_keys("xxx")
       DynamoForum.find_element_by_id("btnSubmit").click()

enter image description here