python登陸126郵箱記錄

來源:互聯網
上載者:User

標籤:報錯   body   擷取   webdriver   python   select   art   family   輸入   

python登陸126郵箱

因為剛開始學習自動化測試,所以一直是跟著蟲師的《Selenium的自動化測試實戰》來學習的,在其中碰到利用python登陸126郵箱,實踐時發現最新一版的126郵箱不能根據id進行自動化登陸,解決步驟如下所示:

1.第一次選擇使用css定位的方式進行登陸,結果報錯 An invalid or illegal selector was specified(指定了無效或非法的選取器)

2.之後又使用xpath定位,結果又報錯Unable to find element with xpath == //input[@name=‘email‘],從網上查,發現126郵箱登陸框是在一個iframe架構中,必須要在代碼中加入如下所示代碼

driver.switch_to_frame("x-URS-iframe")

3.當我運行代碼看到輸入框中開始輸入代碼中預設的內容時,結果發現My Code無法擷取到登陸按鈕的點擊事件(淚奔~~~),找了半天終於找到解決方案,代碼如下所示:

from selenium import webdriverfrom selenium.webdriver.common import keysimport timedriver=webdriver.Ie()driver.get("http://www.126.com")driver.switch_to_frame("x-URS-iframe")driver.find_element_by_xpath("//input[@name=‘email‘]").clear()driver.find_element_by_xpath("//input[@name=‘email‘]").send_keys("username")driver.find_element_by_xpath("//input[@name=‘password‘]").clear()driver.find_element_by_xpath("//input[@name=‘password‘]").send_keys("password")driver.find_element_by_xpath("//input[@name=‘password‘]").send_keys(keys.Keys.ENTER)

 

 

 

 

 

 

參考連結:http://blog.csdn.net/miouqi/article/details/68950257

 

python登陸126郵箱記錄

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.