简体   繁体   English

NoSuchElementException:无论我使用哪个选择器(xpath、css_selector、fullXpath 等),Selenium 都无法找到搜索栏

[英]NoSuchElementException: Selenium unable to locate search bar regardless of which selector I use (xpath, css_selector, fullXpath etc..)

I'm trying to automate search procedure on facebook.我正在尝试在 facebook 上自动化搜索过程。 I used the following code我使用了以下代码

search = driver.find_element_by_xpath('//*[@id="mount_0_0_ij"]/div/div[1]/div/div[2]/div[2]/div/div/div[1]/div/div/label/input')
search.send_keys('foo') # search for 'foo'
submit = driver.find_element_by_css_selector('#jsc_c_11 > div > a > div > div.hpfvmrgz.g5gj957u.buofh1pr.rj1gh0hx.o8rfisnq > span > span')
submit.click()

Note that I had attempted the same procedure beforehand using请注意,我之前曾尝试使用相同的程序

WebDriverWait(f.browser, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="mount_0_0_ij"]/div/div[1]/div/div[2]/div[2]/div/div/div[1]/div/div/label/input'))).send_keys("foo")

To no avail.无济于事。 I keep getting the same error我不断收到同样的错误

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="mount_0_0_ij"]/div/div[1]/div/div[2]/div[2]/div/div/div[1]/div/div/label/input"} NoSuchElementException:消息:没有这样的元素:无法定位元素:{"method":"xpath","selector":"///*[@id="mount_0_0_ij"]/div/div[1]/div/div[ 2]/div[2]/div/div/div[1]/div/div/label/input"}

with a TimeoutException for the last entry.最后一个条目有一个 TimeoutException 。

I have managed to automate login using selenium but these NoSuchElementExceptions occur so frequently, I'm starting to wonder if there's a problem with my device我已经设法使用 selenium 自动登录,但这些NoSuchElementExceptions发生得如此频繁,我开始怀疑我的设备是否有问题

Note : the following code works just fine for my coworkers注意:以下代码适用于我的同事

If it is the facebook Search Facebook which is located on the left corner top side , you can use the belwo css_selector :如果是位于左上角的 facebook Search Facebook ,则可以使用 belwo css_selector :

input[name='global_typeahead']

code :代码 :

wait = WebDriverWait(driver, 10)
search = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='global_typeahead']")))
search.send_keys('foo')

Imports :进口:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

PS :- Those css or xpath are not looking reliable, they may work or may not work, always try to write your own locators using axes. PS :- 那些 css 或 xpath 看起来不可靠,它们可能有效也可能无效,总是尝试使用轴编写自己的定位器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 selenium 无法使用方法定位元素:无法通过 id、css_selector、xpath、链接文本找到元素 - selenium Unable to locate element using methods: cannot find elements by id, css_selector, xpath, link text 无法使用python在硒中使用CSS_SELECTOR定位元素 - Unable to locate the element using CSS_SELECTOR in selenium using python Selenium/Python 无法在 CSS_SELECTOR 中使用 `:contains()` - Selenium/Python Unable to use `:contains()` in CSS_SELECTOR 硒css_selector斗争 - selenium css_selector struggle Selenium,W​​ebdriver-找不到-xpath / css_selector /…python - Selenium, webdriver - can't find - xpath/css_selector/… python Selenium Python - Text() 适用于 Xpath 但不适用于 CSS_Selector - Selenium Python - Text() works with Xpath but does not with CSS_Selector selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素:{“方法”:“css选择器”,“选择器”:“.ui流感~”} - selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".ui flu~"} Selenium NoSuchElementException-无法找到元素:{“方法”:“ css选择器”,“选择器”:“ [[名称=”电子邮件地址”]”} - Selenium NoSuchElementException - Unable to locate element: {“method”:“css selector”,“selector”:“[name=”emailAddress“]”} selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素:{"method":"xpath","selector":""} - selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":""} Selenium CSS_Selector寻找具有特定文本的元素,结果是'NoSuchElementException' - Selenium CSS_Selector looking for an element with specific text is turning out a 'NoSuchElementException'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM