Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python的Find元素突然停止工作_Python_Selenium - Fatal编程技术网

Python的Find元素突然停止工作

Python的Find元素突然停止工作,python,selenium,Python,Selenium,更新:找到了。如果我在Server2012实例上以管理员身份运行脚本,它将正常工作。从昨天到今天,服务器上一定发生了某些更改,从而更改了某些权限 使用selenium时,我无法在Windows Server 2012上获取所需的元素。我只得到“没有”。如果我试图访问一个不存在的元素,我会得到相应的NoTouchElementException,因此它似乎正在找到它 直到昨天,一切都很顺利,由于某种原因,今天就停止了。当我在Windows10上运行它时,代码也可以正常工作 我在共享磁盘上使用相同的

更新:找到了。如果我在Server2012实例上以管理员身份运行脚本,它将正常工作。从昨天到今天,服务器上一定发生了某些更改,从而更改了某些权限

使用selenium时,我无法在Windows Server 2012上获取所需的元素。我只得到“没有”。如果我试图访问一个不存在的元素,我会得到相应的NoTouchElementException,因此它似乎正在找到它

直到昨天,一切都很顺利,由于某种原因,今天就停止了。当我在Windows10上运行它时,代码也可以正常工作

我在共享磁盘上使用相同的iedriver,所以不是这样

下面是html代码。在我打这个电话之前或之后,一切都没有改变

<div id="root">some text</div>

尝试使用
textContent

print(browser.find_element_by_id("root").get_attribute('textContent'))

更新:找到了。如果我在Server2012实例上以管理员身份运行脚本,它将正常工作。从昨天到今天,服务器上一定发生了某些更改,从而更改了某些权限

请花一分钟时间将您的问题正确格式化。您将代码格式化为引号,而不是使其难以阅读的代码。你的问题也不清楚。您发布的代码显示找不到元素。。。因此,第一行显示
None
,下一行显示错误。很明显,该元素已经不存在,您需要添加等待,或者页面的格式已经更改(可能将该元素移动到
IFRAME
),等等。那么问题是什么呢?我们无法提供没有HTML可查看的新定位器。对于格式设置,我们深表歉意。输入我的问题的表单会自动执行此操作。问题是找到了元素,但没有返回任何元素——但仅在windows 2012计算机上返回。如果我输入了一个无效的ID,那么它会按预期返回一个NoTouchElementException。在windows 10机器上,它按预期工作,并返回元素和内部文本页面是否会每隔一段时间自动刷新?很难说问题出在哪里。您必须搜索DOM并查看预期的元素是否实际存在。我不确定
None
在这个上下文中是什么意思,或者它实际上应该返回什么。我会执行类似于
print(elem.getAttribute(“innerHTML”)
的操作。执行
print(driver.page\u source)
时,您会看到什么?返回以下内容:AttributeError:'NoneType'对象没有属性'get\u attribute'
print(browser.find_element_by_id("root").text)

Traceback (most recent call last):
  File "<pyshell#17>", line 1, in <module>
    browser.find_element_by_id("root").print
AttributeError: 'NoneType' object has no attribute 'text'
print(browser.find_element_by_id("none"))

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    print(browser.find_element_by_id("none"))
  File "C:\Users\A1B4CZZ\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 360, in find_element_by_id
    return self.find_element(by=By.ID, value=id_)
  File "C:\Users\A1B4CZZ\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
    'value': value})['value']
  File "C:\Users\A1B4CZZ\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\A1B4CZZ\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to find element with css selector == [id="none"]
>>> elems = browser.find_elements_by_xpath('//*')
>>> print(len(elems))
8559

>>> for elem in elems:
    print(elem)


None
None
None
None
None
None
None
None
None
None
None
None
.
.
.
print(browser.find_element_by_id("root").get_attribute('textContent'))