login.php
はパス値
<script type="text/javascript">
function validate(){
var res=confirm("Are you sure");
if(res)
return true;
else
return false;
}
</script>
を提出したときに、私はセレンを使用してPythonスクリプトからログインしようとしています次の関数を呼び出します。ログインをクリックすると、次のスクリプトが呼び出され、ログインするには「はい」を選択する必要があります。
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
browser = webdriver.Firefox()
browser.get("webpage/login.php")
username = browser.find_element_by_id("id")
password = browser.find_element_by_id("pass")
username.send_keys("username")
password.send_keys("password")
login_attempt = browser.find_element_by_xpath("//*[@type='submit']")
login_attempt.submit()
#I want to send yes to the `validate` function and the
#then then again do browser.get("webpage/home.php") to scrape info from a html tag
#print(login_attempt.submit())
私は、私がやろうとしていることに対して比較的新しいです。より良い方法があれば、提案がよく受けられます。
すでに投稿された回答を試してください。 'https://stackoverflow.com/questions/46105357/how-to-handle-new-poped-up-browser-window-with-java-selenium/46109119#46109119' –
[this ](https://stackoverflow.com/a/29052586/3989888)は便利だが、 'xpath(u '// input [@ value =" OK "]')。 。だから 'window.confirm'の' Ok'ボタンの要素の型は何ですか12. –