我已经尝试了几个小时,点击网页上的一个按钮,下面的代码,但无法找到解决方案。
我试着用Xpath,full-Xpath,class来点击它,但是不起作用。我听说“iframe”可能会出错,但是我没有看到任何名为“frame”的标记(或者iframe标记可能在文档中使用不同的名称??)
供您参考,当我按下按钮时,它并不指向新页面,而是出现一个弹出窗口来填写内容。
错误消息
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 type="button" class="btn btn-warning btn-sm" id="btnReleaseVendorInfoModal"> 반출기본정보 수정</button>
Python代码
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()
1条答案
按热度按时间iq3niunx1#
要在***clickable***元素上执行click(),需要为element_to_be_clickable()引入WebDriverWait,可以使用以下locator strategies之一:
参考文献
您可以在以下位置找到一些关于NoSuchElementException的相关讨论: