Get real XML source in Selenium Chrome Driver

你说的曾经没有我的故事 提交于 2019-12-25 18:24:06

问题


I am using selenium and ChromeDriver to test a XML response.

The response is like this:

<?xml version="1.0" encoding="UTF-8"?>
<d>test</d>

But If I get that URL in selenium, chrome will render the XML automatically, making the page_source dirty.

>>> from selenium import webdriver
>>> b=webdriver.Chrome()
>>> b.get('http://127.0.0.1/test.xml')
>>> b.page_source
'<?xml version="1.0" encoding="UTF-8"?><html xmlns="http://www.w3.org/1999/xhtml"><head><style id="xml-viewer-style">/* Copyright 2014 The Chromium Authors. All rights reserved.\n * Use of this source code is governed by a BSD-style license that can be\n * found in the LICENSE file...'

(You can see that chrome adds a "XML viewer" to the page source)

What is the best practice to get the real source of the XML?

ps. This XML is returned by a chrome extension I will use selenium to test, so "use requests or urllib" is not a solution.


回答1:


All right, my solution is:

b.execute_script('return document.getElementById("webkit-xml-viewer-source-xml").innerHTML')

It's certainly not a good practice, but at least working.



来源:https://stackoverflow.com/questions/44370831/get-real-xml-source-in-selenium-chrome-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!