Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
126 views
in Technique[技术] by (71.8m points)

python - Selenium webdriver using switch_to_windows() and printing the title doesn't print the title.

Here is the code

for handle in browser.window_handles:
    print "Handle = ",handle
    browser.switch_to_window(handle);
    elem = browser.find_element_by_tag_name("title")
    print elem.get_attribute("value")

I am getting the following output

Handle =  {564f8459-dd20-45b8-84bf-97c69f369738}
None
Handle =  {85338322-5e58-4445-8fe3-3e822d5a0caf}
None

After getting the handle I switch to the window and print the title. Why am I not seeing any title. Won't there be any titles? When I see the html source for the page I see the title tag though.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
driver.switch_to_window(driver.window_handles[-1])
title=driver.title

You can do it simply use the code above. driver.window_handles[-1] would get the lastest window.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...