大佬 请教一下,这种没有任何属性的元素如何取值呢,用获取元素文本也取不到,还有其他方式能取到这个值么,我看元素定位方式里没有文本方式定位

提问 16 168
无心
无心 LV3 9月23日 16:13 发表
<p><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">2024-09-23 07:47:12.875485 - Debug - WEB操作[断言元素属性]开始</span><br style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;" data-filtered="filtered"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">2024-09-23 07:47:13.332473 - Error - 无法定位元素 'By:&nbsp;</span><img src="http://talk-cdn.liumatest.cn/0d8e8ae2-b0e3-411f-b8f7-e1e7b4159d15.png" style="max-width: 100%;"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">xpath Expression: //*[@id="ice-container"]/div/div/div[2]/div[1]/div[2]/div[2]/text()'</span></p><p><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">2024-09-23 07:47:13.332580 - Debug - WEB操作[断言元素属性]结束</span><br style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;" data-filtered="filtered"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">2024-09-23 07:47:13.787756 - Error - Message: invalid selector: The result of the xpath expression "//*[@id="ice-container"]/div/div/div[2]/div[1]/div[2]/div[2]/text()" is: [object Text]. It should be an element. (Session info: chrome=91.0.4472.77)</span><br style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;" data-filtered="filtered"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">2024-09-23 07:47:13.798658 - Error - 程序错误信息:</span><br style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;" data-filtered="filtered"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">Traceback (most recent call last):</span><br style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;" data-filtered="filtered"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">File "/usr/local/lib/python3.8/unittest/case.py", line 60, in testPartExecutor yield</span><br style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;" data-filtered="filtered"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">File "/usr/local/lib/python3.8/unittest/case.py", line 676, in run self._callTestMethod(testMethod)</span><br style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;" data-filtered="filtered"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">File "/usr/local/lib/python3.8/unittest/case.py", line 633, in _callTestMethod method()</span><br style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;" data-filtered="filtered"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">File "/liuma/lm/lm_case.py", line 29, in testEntrance WebTestCase(test=self).execute()</span><br style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;" data-filtered="filtered"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">File "/liuma/core/web/testcase.py", line 30, in execute self.loop_execute(self.case_message['optList'], [])</span><br style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;" data-filtered="filtered"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">File "/liuma/core/web/testcase.py", line 64, in loop_execute raise e</span><br style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;" data-filtered="filtered"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">File "/liuma/core/web/testcase.py", line 57, in loop_execute step.execute()</span><br style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;" data-filtered="filtered"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">File "/liuma/core/web/teststep.py", line 39, in execute self.result = func(self.test, self.driver, **opt_content)</span><br style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;" data-filtered="filtered"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">File "/liuma/core/web/find_opt.py", line 295, in assert_ele_attribute return Assertion(test, driver).assert_ele_attribute(kwargs["element"]["element"], kwargs["data"]["name"],</span><br style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;" data-filtered="filtered"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">File "/liuma/core/web/driver/assertionOpt.py", line 166, in assert_ele_attribute raise e</span><br style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;" data-filtered="filtered"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">File "/liuma/core/web/driver/assertionOpt.py", line 163, in assert_ele_attribute actual = self.find_element(element).get_attribute(name)</span><br style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;" data-filtered="filtered"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">File "/liuma/core/web/driver/__init__.py", line 18, in find_element raise e</span><br style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;" data-filtered="filtered"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">File "/liuma/core/web/driver/__init__.py", line 13, in find_element element = self.driver.find_element(*tuple(ele))</span><br style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;" data-filtered="filtered"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 976, in find_element return self.execute(Command.FIND_ELEMENT, {</span><br style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;" data-filtered="filtered"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response)</span><br style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;" data-filtered="filtered"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace)</span><br style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;" data-filtered="filtered"><span style="color: rgb(96, 98, 102); font-family: Avenir, Helvetica, Arial, sans-serif;">selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: The result of the xpath expression "//*[@id="ice-container"]/div/div/div[2]/div[1]/div[2]/div[2]/text()" is: [object Text]. It should be an element. (Session info: chrome=91.0.4472.77)</span><br data-filtered="filtered"></p>
收藏(0)  分享
相关标签: 元素定位 提问
注意:本文归作者所有,未经作者允许,不得转载
16个回复
  • 无心
    无心 LV3 (楼主)
    9月23日 17:00
    我其他有属性的元素是能正常定位的。。。他这个元素也不是图片,就只是一个文本。。如果需要我可以给大佬远程哈
    0 0
  • Chras-fu
    9月26日 08:49
    这种具体写用例的问题只能自行研究
    0 1
  • 无心
    无心 LV3 (楼主)
    9月29日 11:14
    可能我没表达清楚,python代码直接定位元素时候不是可以用文本方式定位嘛,我意思是这个定位方式这块能不能加一个根据文本定位,我以为这里面是不是有我不懂的定位功能啥的所有先问一下子,img[http://talk-cdn.liumatest.cn/20e7a0fe-1644-46da-8529-2f35525e4ce7.png]
    0 10
  • 无心
    无心 LV3 (楼主)
    9月29日 11:58
    img[http://talk-cdn.liumatest.cn/418a5504-6bce-4080-bc3d-ba1306a60920.png]
    0 0
  • 无心
    无心 LV3 (楼主)
    9月29日 13:53
    img[http://talk-cdn.liumatest.cn/d7331b5e-cfbf-421a-a79e-180aef2c293c.png]
    0 0