ここにログインするセレンを使ってPythonで自動スクリプトを作成したいと思います:https://www.netflix.com/Login。 私はこのコードを試してみた:netflixにログインする自動スクリプトを作成します
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("https://www.netflix.com/Login")
while True:
element = driver.find_element_by_css_selector("ui-text-input[name = 'email']")
driver.execute_script("arguments[0].setAttribute('value','test1')", element)
element2 = driver.find_element_by_css_selector("ui-text-input[name = 'password']")
driver.execute_script("arguments[0].setAttribute('value','test1')", element2)
driver.refresh()
しかし、それはエラーがこのコード行で発生した発生します
element = driver.find_element_by_css_selector("ui-text-input[name = 'email']")
:だから、このコード行に問題があります
Traceback (most recent call last):
File "netflixlogin.py", line 6, in <module>
element = driver.find_element_by_css_selector("ui-text-input[name = 'email']")
File "/home/user/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 437, in find_element_by_css_selector
return self.find_element(by=By.CSS_SELECTOR, value=css_selector)
File "/home/user/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 752, in find_element
'value': value})['value']
File "/home/user/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/home/user/.local/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"css selector","selector":"ui-text-input[name = 'email']"}
Stacktrace:
at FirefoxDriver.prototype.findElementInternal_ (file:///tmp/tmpk_odq6d0/extensions/[email protected]/components/driver-component.js:10770)
at FirefoxDriver.prototype.findElement (file:///tmp/tmpk_odq6d0/extensions/[email protected]ode.com/components/driver-component.js:10779)
at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmpk_odq6d0/extensions/[email protected]/components/command-processor.js:12661)
at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmpk_odq6d0/extensions/[email protected]/components/command-processor.js:12666)
at DelayedCommand.prototype.execute/< (file:///tmp/tmpk_odq6d0/extensions/[email protected]/components/command-processor.js:12608)
誤った構文ですか?私は最近、セレンを使用して開始し、私はまだ非常に良いないですので
はないエラーでSCRIPTを更新しましたが、それはまだ動作しません:
解決しようfrom selenium import webdriver
driver = webdriver.Firefox()
driver.get("https://www.netflix.com/Login")
while True:
element = driver.find_element_by_css_selector("form.login-form input[name=email]")
driver.execute_script("arguments[0].setAttribute('value','test1')", element)
element2 = driver.find_element_by_css_selector("form.login-form input[name=password]")
driver.execute_script("arguments[0].setAttribute('value','test1')", element2)
driver.refresh()
。 WORKING SCRIPT:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("https://www.netflix.com/it/")
login = driver.find_element_by_css_selector(".authLinks.signupBasicHeader")
login.click()
element = driver.find_element_by_name("email")
element.send_keys("[email protected]")
submit = driver.find_element_by_css_selector(".btn.login-button.btn-submit.btn-small")
submit.click()
element2 = driver.find_element_by_name("password")
element2.send_keys("test1")
submit2 = driver.find_element_by_css_selector(".btn.login-button.btn-submit.btn-small")
submit2.click()
OKおかげで、今ではすべてのエラーを表示しませんが、コマンドでのすべての電子メールTEST1とパスワードTEST1を書き込みません:driver.execute_script( "引数は[0] .setAttribute(『値』、 'test1') "、要素) – CatchJoul