xpathで正しい要素を取得できないため、エラーが発生します。 Webハンドルが変更されましたか? イメージをクリックできますか?私はエラーを解釈する方法を理解していません。セレンのリンクのない年齢確認をクリックする方法
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
driver = webdriver.Chrome()
#browser.get('https://ebs.lcb.state.pa.us/OA_HTML/AppsLocalLogin.jsp')
driver.get('http://www.finewineandgoodspirits.com')
assert 'Fine Wine & Good Spirits: Shop Online for Wine and Spirits in Pennsylvania' in driver.title
browser.find_element_by_xpath("xpath=//div[@id='ageVerify']/img[@alt='Yes']").click()
InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression xpath=//div[@id='ageVerify']/img[@alt='Yes'] because of the following error: TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type. (Session info: chrome=59.0.3071.115) (Driver info: chromedriver=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 6.1.7601 SP1 x86_64)
まずオフをクリックして要素あなたが存在をターゲットにしているところHTMLが切り取らにあなたの質問を更新することができました。次に、別の 'WebElement'ロケータを使用します。ブラウザのコンソールを開き、セレクタが有効かどうかを確認するためにjQueryを使い始めます( '$ x(// div [@ id = 'ageVerify']/img [@ alt = 'はい']' div#ageVerify img [alt = "はい"]) 'CSSパスの場合)。あなたのエラーはそれ以上冗長ではありません。 ( 'xpath exp ...で要素を見つけることができません。これは、セレクタがうまくいきません) – iamdanchiv