Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.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 Selenium找不到元素_Python_Selenium - Fatal编程技术网

Python Selenium找不到元素

Python Selenium找不到元素,python,selenium,Python,Selenium,我在网页上查找用户名字段时遇到一些问题 使用按名称/类查找元素会提示我“无此类元素”错误 在做了很多手脚之后,我仍然无法让它工作。在我使用相同方法的任何其他网页上都没有这个问题。希望任何人都能帮助我 <input type="text" class="_ph6vk _o716c" aria-describedby="" aria-label="Telefoonnummer, gebruikersnaam of e-mailadres" aria-required="true" autoca

我在网页上查找用户名字段时遇到一些问题

使用按名称/类查找元素会提示我“无此类元素”错误

在做了很多手脚之后,我仍然无法让它工作。在我使用相同方法的任何其他网页上都没有这个问题。希望任何人都能帮助我

<input type="text" class="_ph6vk _o716c" aria-describedby="" aria-label="Telefoonnummer, gebruikersnaam of e-mailadres" aria-required="true" autocapitalize="off" autocorrect="off" autocomplete="username" maxlength="30" name="username" placeholder="Telefoonnummer, gebruikersnaam of e-mailadres" value="">
上面的HTML表示我要查找的元素。

请尝试以下操作:

driver.find_element_by_css_selector("input._ph6vk._o716c")
这行不通:

find_element_by_class("_ph6vk _o716c")

因为它们是两个不同的类。

如果页面加载/呈现速度较慢,请指示驱动程序等待5秒钟,以便加载元素:

driver.implicitly_wait5

显式获取输入:

driver.find\u元素\u by\u xpath//input[contains@class,“_ph6vk”]

虽然类名看起来是在每个特定页面加载时动态生成的,但在这种情况下,您必须先计算页面上的输入,然后再计算所需的输入:

驱动程序。通过xpath//输入[1]查找元素


或者在那里写一个完整的绝对XPath。

显示您尝试过的代码可能是元素在框架或iframe中。请检查它。我如何检查元素是否在iframe中?@andersson driver.find_element_by_nameuname和driver.find_element_by_xpath//a[@type='text']通过查看页面源并搜索“frame”,结果为0。应在答案中添加一些上下文,并使用“backticks”格式化代码。使用and检查第一个xpath中是否包含两个类不是更好吗?Zeinab,这取决于“_ph6vk”类中是否存在其他输入。实际上,如果您想同时使用这两个类,那么最好使用//input[@class=''ph6vk\uo716c']作为xpath。