簡體   English   中英

正確的xpath但find_element_by_xpath失敗python

[英]correct xpath yet find_element_by_xpath fails python

我正在搜索的元素的xpath是正確的。

它之前的所有元素都已找到,並已通過xpath對它們執行了操作。

但是,對於此實例,xpath定位失敗。 當我在Selenium中搜索該網站時,幾乎可以肯定該網站是否存在。

有人對此有經驗嗎? 我可以指出一個方向來學習更多有關它,以及如何解決它。

我正在自動化的網站是facebook.com

我的鼠標懸停在我要查找的表格上,並在下面的圖片中輸入 不,我不擔心您看到我的Facebook

相關代碼如下:

    # from facebook homepage search search for the group
waitForElements(['homepageSearchBarsearchButton'])  #STACK OVERFLOW CODE FAILS HERE
element = driver.find_element_by_xpath((xpath['homepageSearchField']))
element.send_keys(passedText['homepageSearchBarInput'])
time.sleep(randomWait())
element = driver.find_element_by_xpath(xpath['homepageSearchBarsearchButton'])
element.click()

等待下面的元素功能

def waitForElements(xpaths = [], *args):
elementLoad = None

for x in xpaths:
 # noinspection PyRedeclaration
 elementLoad =  WebDriverWait(driver,20).until(EC.presence_of_element_located((By.XPATH, xpath[x])))

故障跟蹤如下:

  File "/home/honeytoes/PycharmProjects/Chicags20sEarly30s/lookingForTagCompliance/lookingForTagCompliance/workingFile.py", line 108, in <module>
        element = driver.find_element_by_xpath(xpath['groupSearchField'])
      File "/home/honeytoes/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 258, in find_element_by_xpath
        return self.find_element(by=By.XPATH, value=xpath)
      File "/home/honeytoes/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 712, in find_element
        {'using': by, 'value': value})['value']
      File "/home/honeytoes/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 201, in execute
        self.error_handler.check_response(response)
      File "/home/honeytoes/.local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 181, in check_response
        raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"xpath","selector":".//*[@id='u_jsonp_5_2']/span/span/input"}
    Stacktrace:

謝謝

我們如何基於placeholder屬性創建替代的可讀選擇器:

//input[@placholder="Search this group"]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM