I am trying to take information inside the tag.
<script type="text/javascript"> INFO </script>
More specifically:
<!DOCTYPE html>
<html lang="en" class="js logged-in client-root">
<head>...</head>
<body class style ="position: fixed; top: -265px; width: 100%;">
<span id="react-root" aria-hidden="true">...</span>
<script type="text/javascript> This is the tag i want. </script>
<script type="text/javascript>
window.__initialDataLoaded(window._sharedData); </script>
...
I am trying this but no luck:
browser = webdriver.Chrome()
info = browser.find_element_by_xpath("//script[@type='text/javascript']")
print(info.text) //prints nothing
I am trying to take information inside the tag.
<script type="text/javascript"> INFO </script>
More specifically:
<!DOCTYPE html>
<html lang="en" class="js logged-in client-root">
<head>...</head>
<body class style ="position: fixed; top: -265px; width: 100%;">
<span id="react-root" aria-hidden="true">...</span>
<script type="text/javascript> This is the tag i want. </script>
<script type="text/javascript>
window.__initialDataLoaded(window._sharedData); </script>
...
I am trying this but no luck:
browser = webdriver.Chrome()
info = browser.find_element_by_xpath("//script[@type='text/javascript']")
print(info.text) //prints nothing
Share
Improve this question
edited May 18, 2018 at 15:13
Rolando Cruz
2,7841 gold badge17 silver badges24 bronze badges
asked May 18, 2018 at 14:10
doruksahindoruksahin
3861 gold badge5 silver badges12 bronze badges
7
|
Show 2 more comments
1 Answer
Reset to default 17Seems like this is the expected behavior. See here:
This is working correctly.
WebElement#getText
returns the visible text that a user can see. The user cannot see text in a<script>
tag, so it is not returned bygetText
. You can still access contents of the tag through JavaScript
So you will have to do something like this:
info.get_attribute('innerHTML')
outerHTML
– undetected Selenium Commented May 18, 2018 at 14:26