硒无法找到元素,但肯定存在

发布于 2025-02-12 14:09:28 字数 1659 浏览 1 评论 0原文

我尝试了Stackoverflow上的所有解决方案,但是仍然有同样的问题。

我正在尝试从Dropbox中选择一个特定的选项。看起来像这样: 单击以查看dropbox。

属于此Dropbox的HTML如下:

<td ct="GLC" lsdata="{1:'STANDARD'}" id="WD18" class="lsContainerCell lsGLCTopVAlign lsContainerCellVAlign--top  urLayoutDefault--grid" valign="TOP" align="left" style="white-space:normal;"><span id="WD19-r" class="lsField lsField--standalone lsField--explicitwidth lsField--hasellipsis lsField--hashelp lsField--list lsField--focus lsField--interactiontarget" aria-live="assertive" style=""><input id="WD19" ct="CB" lsdata="{2:'WD1A',3:'10',4:'2021\x2f2022',27:'WD17'}" lsevents="{Select:[{ResponseData:'delta',EnqueueCardinality:'single'},{}]}" type="text" autocomplete="off" tabindex="0" ti="0" class="lsField__input" readonly="" value="2021/2022" role="combobox" aria-haspopup="listbox" aria-readonly="false" aria-controls="WD1A" aria-expanded="false" aria-autocomplete="list" style="width:150px;" title=""><span id="WD19-btn" class="lsField__help" tabindex="-1" ti="-1" aria-hidden="true" role="button"></span></span></td>

我尝试过的任何事情都没有工作,因为硒无法找到元素。我已经尝试了by.id和by.xpath。我尝试的最后一件事是:

driver.find_element(by.xpath,“/html/html/body/table/tbody/tr/td/td/div/div/div/div [1]/span/span/span/span/span/span/table/table/tbody /tr [2]/td/table/tbody/tr [1]/td [2]”)

但我仍然在千次遇到相同的错误:

Message: no such element: Unable to locate element

预先感谢。

I tried all solutions on Stackoverflow, however still got the same problem.

I am trying to select a specific option from a dropbox. It looks like this:
click to see the dropbox.

The HTML that belongs to this dropbox is as follows:

<td ct="GLC" lsdata="{1:'STANDARD'}" id="WD18" class="lsContainerCell lsGLCTopVAlign lsContainerCellVAlign--top  urLayoutDefault--grid" valign="TOP" align="left" style="white-space:normal;"><span id="WD19-r" class="lsField lsField--standalone lsField--explicitwidth lsField--hasellipsis lsField--hashelp lsField--list lsField--focus lsField--interactiontarget" aria-live="assertive" style=""><input id="WD19" ct="CB" lsdata="{2:'WD1A',3:'10',4:'2021\x2f2022',27:'WD17'}" lsevents="{Select:[{ResponseData:'delta',EnqueueCardinality:'single'},{}]}" type="text" autocomplete="off" tabindex="0" ti="0" class="lsField__input" readonly="" value="2021/2022" role="combobox" aria-haspopup="listbox" aria-readonly="false" aria-controls="WD1A" aria-expanded="false" aria-autocomplete="list" style="width:150px;" title=""><span id="WD19-btn" class="lsField__help" tabindex="-1" ti="-1" aria-hidden="true" role="button"></span></span></td>

Nothing I have tried did work because Selenium can not locate element. I've tried it with By.ID and By.XPATH. Last thing I have tried is this:

driver.find_element(By.XPATH, "/html/body/table/tbody/tr/td/div/div[1]/span/span[1]/table/tbody/tr[2]/td/table/tbody/tr[1]/td[2]")

But I still got the same error for the thousandth time:

Message: no such element: Unable to locate element

Thanks in advance.

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

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

发布评论

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

评论(1

郁金香雨 2025-02-19 14:09:28

尝试此XPath,避免绝对路径(单击元素,获取XPATH -_--)

driver.find_element(By.XPATH, "//td[@ct='GLC']") 

Try this Xpath, avoid absolute path (click element, get xpath -_-)

driver.find_element(By.XPATH, "//td[@ct='GLC']") 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文