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?
CodePudding user response:
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