硒CSSSELECTOR用python编写的增加超时错误

发布于 2025-02-08 09:51:39 字数 635 浏览 4 评论 0原文

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

Wait(driver, 15).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'td:nth-child(2)>input')))
driver.find_element(By.CSS_SELECTOR, 'td:nth-child(2)>input').send_keys(element[0])

搜索网站的CSS的部分HTML脚本 “搜索网站搜索的CSS的部分html脚本”

两个代码都无法正常工作。格式看起来正确。

也许CSS选择器似乎是问题所在?

之前,每次都有不同的输入时,ID属性每次都会更改

当此页面代码提高 timeOutExceptionError

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

Wait(driver, 15).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'td:nth-child(2)>input')))
driver.find_element(By.CSS_SELECTOR, 'td:nth-child(2)>input').send_keys(element[0])

The portion HTML script with CSS searched of the website
the portion HTML script with CSS searched of the website

Both codes are not working. Format looks correct.

Maybe CSS Selector seems to be the problem?

The ID attribute changes every time when there is a different input prior to this page

Code raising a TimeoutExceptionError

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时间你老了 2025-02-15 09:51:39

语法上 css_selector

td:nth-child(2)>input

是正确的,但仍然有合理的错误。

虽然以上 css_selector 第二< td>孩子,但是谁?在这种情况下,您必须提供一个由定位器策略首先,您必须提供一个唯一标识的参考节点 。

例如:

  • 关于< table;标签:

     表TD:nth-​​child(2)>输入
     
  • 相对于< tbody class =“ z-row”> tag:

      tbody.z-row TD:nth-​​child(2)>输入
     

Syntactically the css_selector:

td:nth-child(2)>input

is correct but still have a logical error.

Though the above css_selector indicates immediate <input> descendant of second <td> child, but of whom? In this case you have to provide a reference node uniquely identified by locator strategy first.

As an example:

  • With respect to <table> tag:

    table td:nth-child(2) > input
    
  • With respect to <tbody class="z-row"> tag:

    tbody.z-row td:nth-child(2) > input
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文