私の仕事の役割の中で通常の仕事として、私は多くの場合、ユーザーアカウント内から完全なFacebookアカウントをダウンロードする必要があります。私は自分のワークフローを改善し、可能ならばこれを自動化しようとしています。Facebookアカウントの自動化とPython?
私はサイト上でこのトピックを検索しようとしましたが、多くはログイン部分をカバーしていますが、まだFacebookのポップアップウィンドウを扱う質問を見つけることはできません。私が間違っている場合、私は謝罪し、それに応じて投稿を修正してください。
出発点として、私はPythonの学習を開始することに決めました。これを使用して、セレンとChrome Driverの助けを借りてプロセスをスクリプト化しています。私は、ログインするためのコードを書いて正しいページに移動し、最初のリンク 'コピーをダウンロードする'をクリックしました。しかし、私は、スクリプトを見つけてポップアップウィンドウ内の「Start My Archive」ボタンをクリックするように苦労しています。ここで
は、私はこれまで、私は一番下にコメントアウトしようとしているいくつかの代替コードブロックを含んで使用しているコードは次のとおりです。それが動作している場合
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
#Global Variables
target = "john.doe.7"
username = "[email protected]"
password = "Password"
sleep = 5
#Finds and locates the ChromeDriver
driver = webdriver.Chrome("C:\Python35-32\ChromeDriver\chromedriver.exe")
#Set Chrome Options
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications": 2}
chrome_options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(chrome_options=chrome_options)
#Directs browser to webpage
driver.get('http://www.facebook.com');
#code block to log in user
def logmein():
search_box = driver.find_element_by_name('email')
search_box.send_keys(username)
search_box = driver.find_element_by_name('pass')
search_box.send_keys(password)
search_box.submit()
#code to go to specific URL
def GoToURL(URL):
time.sleep(sleep) # Let the user actually see something!
driver.get(URL);
logmein()
GoToURL('https://www.facebook.com/'+'settings')
link = driver.find_element_by_link_text('Download a copy')
link.click()
#driver.find_element_by.xpath("//button[contains(., 'Start My Archive')]").click()
#driver.find_element_by_css_selector('button._42ft._42fu.selected._42gz._42gy').click()
#driver.find_element_by_xpath("//*[contains(text(), 'Start My Archive')]").click()
#driver.find_element_by_css_selector('button._42ft._42fu.layerConfirm.uiOverlayButton.selected._42g-._42gy').click()
#from selenium.webdriver.common.action_chains.ActionChains import driver
#buttons = driver.find_elements_by_xpath("//title[contains(text(),'Start My Archive')]")
#actions = ActionChains(self.driver)
#time.sleep(2)
#actions.click(button)
#actions.perform()
[マイアーカイブを開始]がWeb要素ではなく、どのウィンドウがポップアップしているのかは、ドライバで処理できません。 Windowsベースのアラートを処理するために使用できるRobotというクラスがあります。参照してください http://www.softwaretestinghelp.com/handle-alerts-popups-selenium-webdriver-selenium-tutorial-16/ –
@KishanPatelリンクとチュートリアルをありがとう。私はこれを介して作業し、それが役立つかどうかを確認します。あなたはweb要素のことについて言及しました。私はそのボタンが1だと思います。私は、このタイプの要素であるかどうかを明確にするのに役立つかもしれない下のページからhtmlを含めました。また、これを動作させるにはjavascriptを使用する必要がありますが、それは確かではありませんか? – JamesLC