51Testing软件测试论坛

标题: python接管指定端口后,定位元素找不到报错 [打印本页]

作者: 测试积点老人    时间: 2021-9-22 11:32
标题: python接管指定端口后,定位元素找不到报错
想写一个简单的上传视频,调用指定端口,跳转链接成功后,找不到元素报错,希望能够给个解决代码方案,源码如下
[attach]134518[/attach]
  1. from selenium import webdriver  
  2. from selenium.webdriver.common.by import By
  3. from selenium.webdriver.chrome.options import Options
  4. url = "https://cp.kuaishou.com/article/publish/video"
  5. chrome_options = Options()
  6. chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9918")
  7. driver = webdriver.Chrome(executable_path=r'./chromedriver.exe', options=chrome_options)
  8. driver.get(url)
  9. driver.find_element(By.XPATH,"//span[text()='上传视频']").click()



  10. 报错日志如下
  11. ```python
  12. Traceback (most recent call last):
  13.   File "E:/chengxu1/2.py", line 14, in <module>
  14.     driver.find_element(By.XPATH,"//span[text()='上传视频']").click()
  15.   File "E:\Program Files\pythpn\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
  16.     'value': value})['value']
  17.   File "E:\Program Files\pythpn\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
  18.     self.error_handler.check_response(response)
  19.   File "E:\Program Files\pythpn\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
  20.     raise exception_class(message, screen, stacktrace)
  21. selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//span[text()='上传视频']"}
  22.   (Session info: chrome=78.0.3904.70)
复制代码



作者: qqq911    时间: 2021-9-23 10:26
这是个debug地址啊
作者: 海海豚    时间: 2021-9-23 14:17
重新定位下元素
作者: jingzizx    时间: 2021-9-23 17:09
重新定位




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2