Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

LINK_TEXT is capitalized but shows in lower case in browser's html code

On this page, the LINK_TEXT ‘DAILY TREASURY PAR YIELD CURVE RATES’ is obviously upper case. However, it shows in lower case as ‘Daily Treasury PAR Yield Curve Rates’ in html generated after Ctrl-U in Chrome. It shows the same way in driver.page_source, where driver is selenium’s webdriver, as well as after passing page_source through Beautiful Soup.

However, selenium is able to recognize the element only if the LINK_TEXT is all upper-case as it is in the browser.

What is going on?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This is because the CSS that applies to h3 elements on the page is making it uppercase:

h3 {
text-transform: uppercase !important;
letter-spacing: 2px !important;
line-height: 1.18 !important;
font-weight: 700 !important;
margin-top: 20px !important;
font-size: 24px !important;
color: #0053a3 !important;
margin: 20px 0 !important; }

The WebDriver’s Get Element Text command is going to grab the text as it’s rendered, which will be affected by whatever CSS rules are acting on it.

Long story short, this is expected behavior in Selenium.

Reference: https://w3c.github.io/webdriver/webdriver-spec.html#get-element-text

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading