gpt4 book ai didi

python - selenium.common.exceptions.NoSuchElementException : Message: no such element: Unable to locate element:

转载 作者:行者123 更新时间:2023-12-01 00:47:35 28 4
gpt4 key购买 nike

XPath 不适用于以下路径代码。

HTML

<span class="voter_details">
<h4 class="v_msg" id="v_msg" style="font-size: 14px;margin-bottom:25px;">Hi, you are here XXXfor in a while, kindly enter your name!</h4>
<input value="" placeholder="Enter your Name" type="text" id="v" name="v" class="form-control name_box" maxlength="20">
</span>

错误

selenium.common.exceptions.NoSuchElementException: Message: no such element: 
Unable to locate element: {"method":"xpath","selector":"//*[@id='v']"}

代码

driver.find_element(driver.find_element(By.XPATH, "//*[@id='v']")).send_keys('random.choice(list)')

最佳答案

使用以下xpath访问输入元素。

driver.find_element_by_xpath("//input[@placeholder='Enter your Name'][@id='v']").send_keys('Ashwani')

或者您可以使用 WebdriverWait 等待元素可单击并发送,然后输入值。

WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//input[@placeholder='Enter your Name'][@id='v']"))).send_keys('Ashwani')

要执行该操作,您需要进行以下导入。

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

关于python - selenium.common.exceptions.NoSuchElementException : Message: no such element: Unable to locate element:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56833813/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com