Selenium cannot find element by name on instagram autorisation page(在Instagram自动化页上找不到元素的名称)
                            本文介绍了在Instagram自动化页上找不到元素的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
                        
                        问题描述
尝试使用Selify处理Instagram自动化页上的用户名输入字段时,出现意外结果。
编码:
from selenium import webdriver
from selenium.webdriver.common.by import By
patch = r'{patch to driver}'
driver = webdriver.Chrome(patch)
driver.get('https://api.instagram.com/oauth/authorize?client_id=965975207687609&redirect_uri=https://6b4c-46-39-51-57.ngrok.io/autos/index.php/&scope=user_profile,user_media&response_type=code')
elem = driver.find_element(By.NAME, 'username')
C:UsersdigitAppDataRoamingMicrosoftWindowsStart MenuProgramsPython 3.10gitdirapiinsta_api.py:54: DeprecationWarning: executable_path has been deprecated, please pass in a Service object   driver = webdriver.Chrome(patch)
DevTools listening on ws://127.0.0.1:58299/devtools/browser/8fd4d931-7cc4-4070-b3f6-3a6a0df9769e Traceback (most recent call last):   File "C:UsersdigitAppDataRoamingMicrosoftWindowsStart MenuProgramsPython 3.10gitdirapiinsta_api.py", line 64, in <module>
    elem = driver.find_element(By.NAME, 'username')   File "C:UsersdigitAppDataLocalProgramsPythonPython310libsite-packagesseleniumwebdriver
emotewebdriver.py", line 1244, in find_element
    return self.execute(Command.FIND_ELEMENT, {   File "C:UsersdigitAppDataLocalProgramsPythonPython310libsite-packagesseleniumwebdriver
emotewebdriver.py", line 424, in execute
    self.error_handler.check_response(response)   File "C:UsersdigitAppDataLocalProgramsPythonPython310libsite-packagesseleniumwebdriver
emoteerrorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="username"]"}   (Session info: chrome=97.0.4692.71)
推荐答案
Instagram Login Page上的用户名字段是一个ReactJS元素。因此,要发送字符序列,您必须为element_to_be_clickable()归纳WebDriverWait,并且可以使用以下Locator Strategies之一:
- 使用css_selector: - driver.get('https://api.instagram.com/oauth/authorize?client_id=965975207687609&redirect_uri=https://6b4c-46-39-51-57.ngrok.io/autos/index.php/&scope=user_profile,user_media&response_type=code') WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='username']"))).send_keys("Ignat")
- 使用XPath: - driver.get('https://api.instagram.com/oauth/authorize?client_id=965975207687609&redirect_uri=https://6b4c-46-39-51-57.ngrok.io/autos/index.php/&scope=user_profile,user_media&response_type=code') WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='username']"))).send_keys("Ignat")
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
这篇关于在Instagram自动化页上找不到元素的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
				 沃梦达教程
				
			本文标题为:在Instagram自动化页上找不到元素的名称
 
				
         
 
            
        基础教程推荐
             猜你喜欢
        
	     - Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 包装空间模型 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
				 
				 
				 
				