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

前端 未结 2 1127
旧巷少年郎
旧巷少年郎 2020-12-06 01:33

Here is the code

for handle in browser.window_handles:
    print \"Handle = \",handle
    browser.switch_to_window(handle);
    elem = browser.find_element_         


        
相关标签:
2条回答
  • 2020-12-06 01:56
    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.

    0 讨论(0)
  • 2020-12-06 01:59

    The title of the page wouldn't be in a value attribute of a title element, it would be the text contents of that element.

    The correct way to access that text would be browser.find_element_by_tag_name("title").text

    Or even easier, just access browser.title.

    0 讨论(0)
提交回复
热议问题