简体   繁体   English

Python Selenium:find_element_by_link_text 不起作用

[英]Python Selenium: find_element_by_link_text doesn't work

I've been using Python's Selenium bindings with PyCharm CE for three years now and never had any problems with its functions.三年来,我一直在使用 Python 的 Selenium 绑定与 PyCharm CE,并且从未遇到过任何功能问题。

But now I'm encountering a very weird error when trying to use find_element_by_link_text as in但是现在我在尝试使用 find_element_by_link_text 时遇到了一个非常奇怪的错误

browser.find_element_by_link_text("Administration").click()

The error reads as followed:错误如下:

selenium.common.exceptions.JavascriptException: Message: javascript error: this.each is not a function

Other find_element_by functions work perfectly fine.其他 find_element_by 函数工作得很好。

After updating all my packages including selenium to 4.0 I received this warning in addition to the above:将包括selenium在内的所有软件包更新到 4.0 后,除了上述内容外,我还收到了以下警告:

UserWarning: find_element_by_* commands are deprecated. Please use find_element() instead
  warnings.warn("find_element_by_* commands are deprecated. Please use find_element() instead")

I downgraded selenium to 3.141.0 again, but then I just receive the this.each error again without any warnings.我再次将selenium降级为 3.141.0,但随后我再次收到this.each错误而没有任何警告。

I also tried other different approaches given by selenium.dev such as我还尝试了 selenium.dev 给出的其他不同方法,例如

browser.find_element(By.LINK_TEXT, value="Administration")

but they don't seem to work either.但它们似乎也不起作用。

What has changed?发生了什么变化? What do I have to change?我必须改变什么? Why do all other similar find_element functions like id/xpath/visible_text/etc.为什么所有其他类似的 find_element 函数都像 id/xpath/visible_text/etc 一样。 work?工作? I'm at my wits' end, and I don't want to rewrite all my find_element_by_link_text calls.我束手无策,我不想重写我所有的 find_element_by_link_text 调用。 :( :(

The function finally works with Chrome 83 Beta and Chromedriver 83, and it looks like the problem was caused by the older Chromedriver version, incorrectly calling prototype.js. function 终于可以与 Chrome 83 Beta 和 Chromedriver 83 一起使用,看起来问题是由旧版 Chromedriver 引起的,错误地调用了prototype.js。

Patch notes for version 83:版本 83 的补丁说明:

"Updated Chromedriver to work correctly with prototype.js." “更新了 Chromedriver 以与prototype.js 一起正常工作。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM