0

I'm trying to get a login script to select a user name input to enter in my user name. After this popup is done there will be another one asking for the password. I'm new to python and web interfaces so I'm having trouble identifying what element of the website I need to select to get this to work. Here is the code I have so far.

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")

The website is opening and the popup is starting but no text is being entered. Here is what my getting as a result:

Traceback (most recent call last):
  File "C:/Users/cjr/PycharmProjects/DynamoForum/DynamoForum.py", line 17, in <module>
    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']")))
  File "C:\Users\cjr\PycharmProjects\DynamoForum\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "C:\Users\cjr\PycharmProjects\DynamoForum\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
    'value': value})['value']
  File "C:\Users\cjr\PycharmProjects\DynamoForum\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\cjr\PycharmProjects\DynamoForum\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//iframe[@id='destination_publishing_iframe_autodesk_0']"}
  (Session info: chrome=72.0.3626.119)
  (Driver info: chromedriver=73.0.3683.20 (8e2b610813e167eee3619ac4ce6e42e3ec622017),platform=Windows NT 10.0.17134 x86_64)

2 Answers 2

0

Basically when you are clicking on login button, you are moving to another window and to access the element in new window you need to switch it from parent window to access this.Try the below code it should work.

    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("[email protected]")
        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

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

4 Comments

To get the next window do I set the window_child variable to a new value? I'm getting element not interable. window_child= DynamoForum.window_handles[1] DynamoForum.switch_to.window(window_child) DynamoForum.find_element_by_id("password").send_keys("xxx") DynamoForum.find_element_by_id("btnSubmit").click()
You have to wait for that element located. wait=WebDriverWait(DynamoForum,20) wait.until(EC.visibility_of_element_located((By.ID,"password"))).send_keys("xxx")
Thanks, I imported expected_conditions and WebDriverWait, but I'm getting this error when I run it. NameError: name 'By' is not defined. Shouldn't that be a part of EC?
from selenium.webdriver.common.by import By
0

You need to switch to the iframe.

e.g.

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')

See the switch_to function here : https://selenium-python.readthedocs.io/api.html?highlight=iframe

For reference:

python selenium cant find iframe xpath

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

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.