2017-10-08 13 views
0

私が望む要素のXPATHを見つけることができますが、それをクリックすることはできません。具体的には、WebDriverExceptionをスローします。Python Seleniumはxpathで要素をクリックします。

from selenium import webdriver 
browser=webdriver.Chrome() 
url='https://fred.stlouisfed.org/categories/32261' 
browser.get(url) 
click=browser.find_element_by_xpath("//a[@title='next page']") 
print(click.get_attribute('title')) 
click.click() 

は、次のエラーを返します:だから enter image description here

+0

)click.click(「前にsend_keys( 『次のページ』) 『を利用すると、』動作していることを – Kyle

答えて

-1

を、XPathはしかし、私は初期しようとしたとき、私は実際にそれを指摘したとは思わない、があった「click.click()を。」よりよい解決策があるかもしれませんが、これは今のところうまくいくようです。

from selenium import webdriver 
    browser=webdriver.Chrome() 
    url='https://fred.stlouisfed.org/categories/32261' 
    browser.get(url) 
    click=browser.find_element_by_xpath("//a[@title='next page']") 
    print(click.get_attribute('title')) 
    click.send_keys('next page') 
    click.click() 
+0

'click.send_keys思われます。 ( '次のページ') 'は問題を実際には解決していない単なる回避策です。 – Andersson

0

現在表示されていないため、必須の要素をクリックすることはできません。あなたはそれをクリックする前に、「次へ」ボタンまでスクロールする必要があります

from selenium import webdriver 
browser = webdriver.Chrome() 
url = 'https://fred.stlouisfed.org/categories/32261' 
browser.get(url) 
next_button = browser.find_element_by_xpath("//a[@title='next page']") 
browser.execute_script("arguments[0].scrollIntoView();", next_button) 
next_button.click() 
+0

こんにちはAndersson、あなたが尋ねるのを嫌うなら、send_keysのようにexecute_scriptを反応させますか?私はexecute_script – Kyle

+0

うん...私はあなたを正しく理解していないと思います。 'send_keys()'フィールドを入力するか、Ctrl + tなどのキーの組み合わせを入力しようとしています。 .. 'execute_script()'はPythonコードから直接JavaScriptコードを実行できるようにします – Andersson

関連する問題