硒元素的位置

2024-10-03 00:28:26 发布

您现在位置:Python中文网/ 问答频道 /正文

是否可以使用Selenium webdriver运行或获取document.elementFromPoint提供的相同功能?在


Tags: 功能seleniumdocumentwebdriverelementfrompoint
1条回答
网友
1楼 · 发布于 2024-10-03 00:28:26

您必须使用JavaScript:

element = driver.execute_script("""
return document.elementFromPoint(arguments[0], arguments[1]);
""", x, y)

这假设x和{}被设置为整数值。在JavaScript端,在第一个参数之后传递给execute_script的参数变成arguments[0], arguments[1]等。(这就是老好人^{} object。Selenium将您提供给execute_script的JavaScript代码包装在一个函数中。)如果找不到任何内容,element将是{}的实例,或者是{}。根据MDN page on this function值,如果:

If the specified point is outside the visible bounds of the document or either coordinate is negative, the result is null.

JavaScript null在Python中变成{}。在

相关问题 更多 >