'Python selenuim) How can I click a button in Modal?

(updated question)

Hi.

I'm trying to click a button but it doesn't work. I guess the error cause by Modal tags. But I'm not sure.

I got "NoSuchElementException" Error before I import "webdriver.support", Now I get "TimeoutException" error. I can't find a way. Can you help me?

ERROR

    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 
Stacktrace:

Button

<button type="button" class="btn btn-warning btn-sm" id="btnReleaseVendorInfoModal"> 반출기본정보 수정</button>

Code

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
import time
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

# Login

# put id
driver = webdriver.Chrome()
driver.get("https://po-management.net/release/list")
time.sleep(1)
elem = driver.find_element_by_name("username")
elem.send_keys(usernameStr)
elem.send_keys(Keys.RETURN)

time.sleep(2)

# put password
password = driver.find_element_by_xpath('//*[@id="input73"]')
try:
    ActionChains(driver).send_keys(Keys.TAB).send_keys(passwordStr).perform()
    password.send_keys(passwordStr)
except StaleElementReferenceException:
    pass
password.send_keys(Keys.RETURN)

# redirect
time.sleep(3)
url = "https://po-management.net/release/list"
driver.get(url)

# search
time.sleep(1)
search = driver.find_element_by_id("releaseSeqArray")
search.send_keys(vrorder)
search.send_keys(Keys.RETURN)

# click1
time.sleep(1)
driver.find_element_by_link_text(vrorder).click()

# click2
time.sleep(3)
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn.btn-warning.btn-sm#btnReleaseVendorInfoModal"))).click()



Solution 1:[1]

You need to switch to the the frame by doing :

# after the frame is activated/displayed
modal = driver.find_element_by_id('releaseCauseInfo')
driver.switch_to_frame(modal)

# all the code that interacts with the modal can come here

NB: Don't forget to switch back to the default window after you're done with the modal by using driver.switch_to_default_content()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eb J