2017-03-05 4 views
0

をチェックし、私はこのコードクリックユーチューブボタンセレンPythonは私のコード

from selenium import webdriver 
from selenium.common.exceptions import TimeoutException 
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0 
from selenium.webdriver.support import expected_conditions as EC# available since 2.26.0 
from selenium.webdriver.common.keys import Keys 

driver = webdriver.Firefox() 
driver.get("https://likesrock.com") 

element = driver.find_element_by_class_name("ytp-large-play-button ytp-button") 
element.click() 

を使用してこのページhttps://likesrock.comでユーチューブvadio

をクリックしてクラスを使用してクリックしようとしていますが、compilorは私にこのerorr

を与えます

トレースバック(最新のコール最後): ファイル "C:¥Users¥youssef¥Desktop¥python project¥xpath.py"、行25、 element = driver.find_ele ( "ytp-large-play-button ytp-button") ファイル "C:\ Python27 \ lib \ site-packages \ selenium \ webdriver \ remote \ webdriver.py"、413行目、find_element_by_class_name return self.find_element (by = CL._NAME、value = name) find_elementのファイル "C:¥Python27¥lib¥site-packages¥selenium¥webdriver¥remote¥webdriver.py"、752行目、 'value':value})[ 'value'] ファイル "C:¥Python27¥lib¥site-packages¥selenium¥webdriver¥remote¥webdriver.py"、行236、実行中 self.error_handler.check_response(応答) ファイル "C:\ Python27 (メッセージ、画面、スタックトレース) NoSuchElementException:メッセージ:ロケールできません(エラーメッセージは表示されません)。 TE素子:.ytp-大プレイボタンYTP-ボタン

あなたは動作しませんfind_element_by_class_name中の化合物クラスを使用している

+0

参照[こちら] (http://stackoverflow.com/q/10658907/7023590)。 – MarianD

答えて

0

助けてください。 find_element_by_xpathにそれを変更し、

driver.find_element_by_xpath("//*[@class='ytp-large-play-button ytp-button']") 

注意を試してみてください - あなたの要素はiFrameの下でそうiframe

driver.switch_to.frame(0) 

完全なコードに切り替えるのを忘れないことです。

driver = webdriver.Firefox() 
driver.get("https://likesrock.com") 
driver.implicitly_wait(20) 
driver.switch_to.frame(0) 
element = driver.find_element_by_xpath("//button[@class='ytp-large-play-button ytp-button']") 
element.click() 
+0

あなたの助けてくれてありがとう、私はちょうど私がtime.sleep(5)を加えたことを忘れないだろうし、それは動作します – jozef

関連する問題