Selenium driver page source is different from browser

i, unfortunately, I can’t post the code to reproduce this problem, because it involves signing up to a site that is not a public site. but my question is more general than code issues. essentially driver.page_sourcedoes not match what is displayed in the browser that it controls. this is not a problem with elements that do not load completely, because I am testing this by executing code line by line in a python terminal. I look at the page source in the browser after right-clicking and go to "view page source", but if I print driver.page_sourceor try find_element_by_[...], it shows a slightly different code with missing whole elements. here is the html:

<nav role="navigation" class="utility-nav__wrapper--right">
<input id="hdn_partyId" value="1965629" type="hidden">
<input id="hdn_firstName" value="CHARLES" type="hidden">
<input id="hdn_sessionId" value="uHxQhlARvzA7N16uh+KJAdNFIcY6D8f9ornqoPQ" type="hidden">
<input id="hdn_cmsAlertRequest" type="hidden" value="Biennial Plus">
<ul class="h-list h-list--middle">
    [...]
</ul>

I need all 4 input element, but the elements hdn_partyIdand hdn_sessionIddo not appear in selenium .page_source, and if I try to get them through .find_element_by_[...], I get aNoSuchElementException

I even checked the check of all the elements inputand listed them, and these 2 did not appear.

Can anyone think why selenium will not provide the same content as direct browsing of the browser that it controls?

: ... Chrome Chromedriver Selenium. , . , python script. , , , , print driver.page_source, , session_id = driver.find_element_by_id('hdn_sessionId'), NoSuchElementException, , .

+6
2

. , javascript, DOM. , " " , . , print driver.page_source driver.find_element_by_[...] , " " , . "" Chrome, , HTML , " ". Javascript partyid = driver.execute_script('return accountdata.$partyId.val();') , . , , , .

+2

'body' , get_attribute('innerHTML') .

0

Source: https://habr.com/ru/post/1681998/


All Articles