3

I've tried for several hours to click a button on webpage with codes below but can't find solution.

I tried to click it with Xpath, full-Xpath, class, but it didn't work. I heard that 'iframe' can occur error, but I don't see any tags named 'frame' (Or can the iframe tag be in the document under a different name??)

For your information, when I press the button, it does not direct to a new page, but a pop-up window appears to fill out the contents.

Error mesaage

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"btnReleaseVendorInfoModal"}
  (Session info: chrome=98.0.4758.102)

button

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

Python 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

# 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)
driver.find_element_by_link_text("btnReleaseVendorInfoModal").click()
TW LEE
  • 31
  • 1
  • 1
  • 4

1 Answers1

1

To click() on the clickable element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn.btn-warning.btn-sm#btnReleaseVendorInfoModal"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn btn-warning btn-sm' and @id='btnReleaseVendorInfoModal']"))).click()
    
  • Using XPATH and the innerText:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[normalize-space(text())='반출기본정보 수정']"))).click()
    
  • Note: You have to add the following imports :

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

References

You can find a couple of relevant discussions on NoSuchElementException in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352