python 如何正确使用2023中的WebDriverWait & presence_of_element_located()?

rqcrx0a6  于 2023-02-21  发布在  Python
关注(0)|答案(1)|浏览(117)

下面是我检测到的HTML:

<div class="arrowPopup arrowPopup-start">
    <div class="arrowPopupText arrowPopupTextTwoLine arrowPopupText-flashOn" style="white-space: nowrap;">type<br>this</div>
</div>

下面是我的代码

element = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CLASS_NAME, 'arrowPopup
arrowPopup-start')))

这个不起作用,20秒后就超时了,有什么帮助吗?

atmip9wb

atmip9wb1#

当然有。这是直接从文件上看出来的,

element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "myDynamicElement"))

我的猜测是您的定位器不正确或元素在IFRAME中,但我们没有足够的信息来确定。

wait = new WebDriverWait(driver, 20) # may need to adjust this based on how much time it takes to get a full game
wait.until(EC.element_to_be_clickable((By.XPATH, "//a[text()='Enter a Typing Race']"))).click();
textToType = wait.until(EC.visibility_of_element_located((By.XPATH, "//div[./span[@unselectable]]"))).text;
typeHere = wait.until(EC.visibility_of_element_located((By.XPATH, "//input[contains(@class,'txtInput')][not(@disabled)]")));
for character in textToType
    typeHere.send_keys(character);
    Thread.Sleep(50); # adjust this to change the typing speed

既然您要求对XPath进行细分

//input[contains(@class,'txtInput')][not(@disabled)]
^ starting at the top of the DOM, find any INPUT
       ^ whose class contains the text 'txtInput'
                                    ^ but does NOT contain the attribute 'disabled'

相关问题