When using the Chrome webdriver with inline styles that have a child selector (>
),
calling browser.page_source
improperly encodes the child selector to >
.
This works properly in Firefox and Safari, but not Chrome.
This example was served with a SimpleHTTPServer in Python (python -m SimpleHTTPServer
). I even went as far
as to try and serve these files with UTF-8 encoding:
python -c "import SimpleHTTPServer; m = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map; m[''] = 'text/plain'; m.update(dict([(k, v + ';charset=UTF-8') for k, v in m.items()])); SimpleHTTPServer.test();"
Given the example files in this gist, I'd expect browser.page_source
to return:
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>
<title>Example page</title>
<meta charset="UTF-8" />
<style>
div > span {
height: 500px;
width: 500px;
padding: 40px;
background-color: blue;
display: block;
color: white;
}
</style>
</head>
<body>
<div class="look-for-me">
The child below
<span>Look at me, I am the child</span>
</div>
</body></html>
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>
<title>Example page</title>
<meta charset="UTF-8" />
<style>
div > span {
height: 500px;
width: 500px;
padding: 40px;
background-color: blue;
display: block;
color: white;
}
</style>
</head>
<body>
<div class="look-for-me">
The child below
<span>Look at me, I am the child</span>
</div>
</body></html>
This bug has been fixed in the latest ChromeDriver version 74.
Please be aware that starting from ChromeDriver version 74 the compatible Chrome version can be launched by that ChromeDriver, so if you use ChromeDriver version 74 then Chrome version 74 can be launched by that ChromeDriver.