1. 程式人生 > >selenium手動執行JavaScript語句

selenium手動執行JavaScript語句

執行 nts elements arch lec select ebs ces 顯示

#coding:utf-8
from selenium import webdriver

def main():
    driver = webdriver.Firefox()
    # 改變網頁顯示文字
    # 網頁源代碼:
    # <html>
    # <body>
        # <div id="result"></div>
        # <script>document.getElementById("result").innerText = ‘Hello World‘;</script>
# </body> # </html> # driver.get(‘http://example.webscraping.com/places/default/dynamic‘) # what = raw_input(‘what:‘) # driver.execute_script("document.getElementById(‘result‘).innerText = ‘%s‘"%what) # input(":") driver.get(http://example.webscraping.com/places/default/search
) driver.find_element_by_id(search_term).send_keys(.) # 將下拉第二個選項改為1000 driver.execute_script("document.getElementById(‘page_size‘).options[1].text = ‘1000‘") driver.find_element_by_id(search).click() driver.implicitly_wait(30) links = driver.find_elements_by_css_selector(#results a
) countries = [link.text for link in links] # driver.close() print countries print len(countries) if __name__ == __main__: main()

selenium手動執行JavaScript語句