Check if a tree is expanded or open (Selenium / Python)












0















I am trying to figure out, how Selenium can check if a tree is open / expanded and if it was successful.



For example we have these lines of code and this is the parent (DOM view using the elements panel).
This is the open tree:
Tree open



by using the console tab I see this and I think this could be useful... but I don't really know how to get the state with [opened: true]



li_attr: {id: "j1_1"}
original: {was_excel_sheet: false, item_name: "Profit and Loss", text: "01
Profit and Loss", mapped: false, initial_order: "01", …}
parent: "#"
parents: ["#"]
state: {loaded: true, opened: true, selected: true, disabled: false}
text: "01 Profit and Loss"
type: "root"


Close tree:
Tree closed










share|improve this question

























  • Hi Gyrospeter. Could you provide the same html you've done above but with it opened and closed. This way we can see what extra classes we have to work with.

    – James Andrews
    Nov 21 '18 at 17:03











  • Of course. Look at the edit. Had to upload pictures, otherwise it would be too much code.

    – Gyrospeter
    Nov 22 '18 at 8:00
















0















I am trying to figure out, how Selenium can check if a tree is open / expanded and if it was successful.



For example we have these lines of code and this is the parent (DOM view using the elements panel).
This is the open tree:
Tree open



by using the console tab I see this and I think this could be useful... but I don't really know how to get the state with [opened: true]



li_attr: {id: "j1_1"}
original: {was_excel_sheet: false, item_name: "Profit and Loss", text: "01
Profit and Loss", mapped: false, initial_order: "01", …}
parent: "#"
parents: ["#"]
state: {loaded: true, opened: true, selected: true, disabled: false}
text: "01 Profit and Loss"
type: "root"


Close tree:
Tree closed










share|improve this question

























  • Hi Gyrospeter. Could you provide the same html you've done above but with it opened and closed. This way we can see what extra classes we have to work with.

    – James Andrews
    Nov 21 '18 at 17:03











  • Of course. Look at the edit. Had to upload pictures, otherwise it would be too much code.

    – Gyrospeter
    Nov 22 '18 at 8:00














0












0








0








I am trying to figure out, how Selenium can check if a tree is open / expanded and if it was successful.



For example we have these lines of code and this is the parent (DOM view using the elements panel).
This is the open tree:
Tree open



by using the console tab I see this and I think this could be useful... but I don't really know how to get the state with [opened: true]



li_attr: {id: "j1_1"}
original: {was_excel_sheet: false, item_name: "Profit and Loss", text: "01
Profit and Loss", mapped: false, initial_order: "01", …}
parent: "#"
parents: ["#"]
state: {loaded: true, opened: true, selected: true, disabled: false}
text: "01 Profit and Loss"
type: "root"


Close tree:
Tree closed










share|improve this question
















I am trying to figure out, how Selenium can check if a tree is open / expanded and if it was successful.



For example we have these lines of code and this is the parent (DOM view using the elements panel).
This is the open tree:
Tree open



by using the console tab I see this and I think this could be useful... but I don't really know how to get the state with [opened: true]



li_attr: {id: "j1_1"}
original: {was_excel_sheet: false, item_name: "Profit and Loss", text: "01
Profit and Loss", mapped: false, initial_order: "01", …}
parent: "#"
parents: ["#"]
state: {loaded: true, opened: true, selected: true, disabled: false}
text: "01 Profit and Loss"
type: "root"


Close tree:
Tree closed







javascript python selenium automation tree






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 7:58







Gyrospeter

















asked Nov 21 '18 at 15:45









GyrospeterGyrospeter

44




44













  • Hi Gyrospeter. Could you provide the same html you've done above but with it opened and closed. This way we can see what extra classes we have to work with.

    – James Andrews
    Nov 21 '18 at 17:03











  • Of course. Look at the edit. Had to upload pictures, otherwise it would be too much code.

    – Gyrospeter
    Nov 22 '18 at 8:00



















  • Hi Gyrospeter. Could you provide the same html you've done above but with it opened and closed. This way we can see what extra classes we have to work with.

    – James Andrews
    Nov 21 '18 at 17:03











  • Of course. Look at the edit. Had to upload pictures, otherwise it would be too much code.

    – Gyrospeter
    Nov 22 '18 at 8:00

















Hi Gyrospeter. Could you provide the same html you've done above but with it opened and closed. This way we can see what extra classes we have to work with.

– James Andrews
Nov 21 '18 at 17:03





Hi Gyrospeter. Could you provide the same html you've done above but with it opened and closed. This way we can see what extra classes we have to work with.

– James Andrews
Nov 21 '18 at 17:03













Of course. Look at the edit. Had to upload pictures, otherwise it would be too much code.

– Gyrospeter
Nov 22 '18 at 8:00





Of course. Look at the edit. Had to upload pictures, otherwise it would be too much code.

– Gyrospeter
Nov 22 '18 at 8:00












1 Answer
1






active

oldest

votes


















0














Okay, I think we've got it.



I've used beautiful soup - https://pypi.org/project/beautifulsoup4/ - which we use to look through the classes of the html.



Once selenium has loaded the page, grab the html and use beautiful soup to turn it into something we can use - a small example of how to do this below



from bs4 import BeautifulSoup

html = driver.page_source
soup = BeautifulSoup(html, 'lxml')


Given that I don't have the html, I've made some small versions that match the images that you've uploaded, below is an open line item known by the class of 'jstree-open'.



open = '''
<div id="tree" class="jstree jstree-1">
<ul class="jstree-container-ul jstree-children">
<li class="jstree-node jstree-last jstree-open">
</li>
</ul>
</div>
'''

open_soup = BeautifulSoup(open)


Using a css selector we can get all the class names of the li:



classes_of_open_li = open_soup.select('div#tree ul.jstree-container-ul li')[0].get('class')
print(classes_of_open_li)

out: ['jstree-node', 'jstree-last', 'jstree-open']


we can then test to see whether 'jstree-open' is one of the classes:



'jstree-open' in classes_of_open_li

out: True


We can then test the opposite:



closed = '''
<div id="tree" class="jstree jstree-1">
<ul class="jstree-container-ul jstree-children">
<li class="jstree-node jstree-last jstree-closed">
</li>
</ul>
</div>
'''
closed_soup = BeautifulSoup(closed)
classes_of_closed_li = closed_soup.select('div#tree ul.jstree-container-ul li')[0].get('class')
'jstree-open' in classes_of_closed_li

out: False


After which is you wanted to select all of the list items you can use the same function to return a list of all list items:



li = '''
<div id="tree" class="jstree jstree-1">
<ul class="jstree-container-ul jstree-children">
<li class="jstree-node jstree-last jstree-closed">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</li>
</ul>
</div>
'''
line_soup = BeautifulSoup(li)
all_line_items = line_soup.select('div#tree ul.jstree-container-ul li ul li')

out: [<li></li>, <li></li>, <li></li>, <li></li>]


Hope this helps!






share|improve this answer
























  • Unfortunately it doesn't work. Get some weird Errors. Will continue with my next tasks and come back later to that problem.

    – Gyrospeter
    Nov 27 '18 at 8:28











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415695%2fcheck-if-a-tree-is-expanded-or-open-selenium-python%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Okay, I think we've got it.



I've used beautiful soup - https://pypi.org/project/beautifulsoup4/ - which we use to look through the classes of the html.



Once selenium has loaded the page, grab the html and use beautiful soup to turn it into something we can use - a small example of how to do this below



from bs4 import BeautifulSoup

html = driver.page_source
soup = BeautifulSoup(html, 'lxml')


Given that I don't have the html, I've made some small versions that match the images that you've uploaded, below is an open line item known by the class of 'jstree-open'.



open = '''
<div id="tree" class="jstree jstree-1">
<ul class="jstree-container-ul jstree-children">
<li class="jstree-node jstree-last jstree-open">
</li>
</ul>
</div>
'''

open_soup = BeautifulSoup(open)


Using a css selector we can get all the class names of the li:



classes_of_open_li = open_soup.select('div#tree ul.jstree-container-ul li')[0].get('class')
print(classes_of_open_li)

out: ['jstree-node', 'jstree-last', 'jstree-open']


we can then test to see whether 'jstree-open' is one of the classes:



'jstree-open' in classes_of_open_li

out: True


We can then test the opposite:



closed = '''
<div id="tree" class="jstree jstree-1">
<ul class="jstree-container-ul jstree-children">
<li class="jstree-node jstree-last jstree-closed">
</li>
</ul>
</div>
'''
closed_soup = BeautifulSoup(closed)
classes_of_closed_li = closed_soup.select('div#tree ul.jstree-container-ul li')[0].get('class')
'jstree-open' in classes_of_closed_li

out: False


After which is you wanted to select all of the list items you can use the same function to return a list of all list items:



li = '''
<div id="tree" class="jstree jstree-1">
<ul class="jstree-container-ul jstree-children">
<li class="jstree-node jstree-last jstree-closed">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</li>
</ul>
</div>
'''
line_soup = BeautifulSoup(li)
all_line_items = line_soup.select('div#tree ul.jstree-container-ul li ul li')

out: [<li></li>, <li></li>, <li></li>, <li></li>]


Hope this helps!






share|improve this answer
























  • Unfortunately it doesn't work. Get some weird Errors. Will continue with my next tasks and come back later to that problem.

    – Gyrospeter
    Nov 27 '18 at 8:28
















0














Okay, I think we've got it.



I've used beautiful soup - https://pypi.org/project/beautifulsoup4/ - which we use to look through the classes of the html.



Once selenium has loaded the page, grab the html and use beautiful soup to turn it into something we can use - a small example of how to do this below



from bs4 import BeautifulSoup

html = driver.page_source
soup = BeautifulSoup(html, 'lxml')


Given that I don't have the html, I've made some small versions that match the images that you've uploaded, below is an open line item known by the class of 'jstree-open'.



open = '''
<div id="tree" class="jstree jstree-1">
<ul class="jstree-container-ul jstree-children">
<li class="jstree-node jstree-last jstree-open">
</li>
</ul>
</div>
'''

open_soup = BeautifulSoup(open)


Using a css selector we can get all the class names of the li:



classes_of_open_li = open_soup.select('div#tree ul.jstree-container-ul li')[0].get('class')
print(classes_of_open_li)

out: ['jstree-node', 'jstree-last', 'jstree-open']


we can then test to see whether 'jstree-open' is one of the classes:



'jstree-open' in classes_of_open_li

out: True


We can then test the opposite:



closed = '''
<div id="tree" class="jstree jstree-1">
<ul class="jstree-container-ul jstree-children">
<li class="jstree-node jstree-last jstree-closed">
</li>
</ul>
</div>
'''
closed_soup = BeautifulSoup(closed)
classes_of_closed_li = closed_soup.select('div#tree ul.jstree-container-ul li')[0].get('class')
'jstree-open' in classes_of_closed_li

out: False


After which is you wanted to select all of the list items you can use the same function to return a list of all list items:



li = '''
<div id="tree" class="jstree jstree-1">
<ul class="jstree-container-ul jstree-children">
<li class="jstree-node jstree-last jstree-closed">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</li>
</ul>
</div>
'''
line_soup = BeautifulSoup(li)
all_line_items = line_soup.select('div#tree ul.jstree-container-ul li ul li')

out: [<li></li>, <li></li>, <li></li>, <li></li>]


Hope this helps!






share|improve this answer
























  • Unfortunately it doesn't work. Get some weird Errors. Will continue with my next tasks and come back later to that problem.

    – Gyrospeter
    Nov 27 '18 at 8:28














0












0








0







Okay, I think we've got it.



I've used beautiful soup - https://pypi.org/project/beautifulsoup4/ - which we use to look through the classes of the html.



Once selenium has loaded the page, grab the html and use beautiful soup to turn it into something we can use - a small example of how to do this below



from bs4 import BeautifulSoup

html = driver.page_source
soup = BeautifulSoup(html, 'lxml')


Given that I don't have the html, I've made some small versions that match the images that you've uploaded, below is an open line item known by the class of 'jstree-open'.



open = '''
<div id="tree" class="jstree jstree-1">
<ul class="jstree-container-ul jstree-children">
<li class="jstree-node jstree-last jstree-open">
</li>
</ul>
</div>
'''

open_soup = BeautifulSoup(open)


Using a css selector we can get all the class names of the li:



classes_of_open_li = open_soup.select('div#tree ul.jstree-container-ul li')[0].get('class')
print(classes_of_open_li)

out: ['jstree-node', 'jstree-last', 'jstree-open']


we can then test to see whether 'jstree-open' is one of the classes:



'jstree-open' in classes_of_open_li

out: True


We can then test the opposite:



closed = '''
<div id="tree" class="jstree jstree-1">
<ul class="jstree-container-ul jstree-children">
<li class="jstree-node jstree-last jstree-closed">
</li>
</ul>
</div>
'''
closed_soup = BeautifulSoup(closed)
classes_of_closed_li = closed_soup.select('div#tree ul.jstree-container-ul li')[0].get('class')
'jstree-open' in classes_of_closed_li

out: False


After which is you wanted to select all of the list items you can use the same function to return a list of all list items:



li = '''
<div id="tree" class="jstree jstree-1">
<ul class="jstree-container-ul jstree-children">
<li class="jstree-node jstree-last jstree-closed">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</li>
</ul>
</div>
'''
line_soup = BeautifulSoup(li)
all_line_items = line_soup.select('div#tree ul.jstree-container-ul li ul li')

out: [<li></li>, <li></li>, <li></li>, <li></li>]


Hope this helps!






share|improve this answer













Okay, I think we've got it.



I've used beautiful soup - https://pypi.org/project/beautifulsoup4/ - which we use to look through the classes of the html.



Once selenium has loaded the page, grab the html and use beautiful soup to turn it into something we can use - a small example of how to do this below



from bs4 import BeautifulSoup

html = driver.page_source
soup = BeautifulSoup(html, 'lxml')


Given that I don't have the html, I've made some small versions that match the images that you've uploaded, below is an open line item known by the class of 'jstree-open'.



open = '''
<div id="tree" class="jstree jstree-1">
<ul class="jstree-container-ul jstree-children">
<li class="jstree-node jstree-last jstree-open">
</li>
</ul>
</div>
'''

open_soup = BeautifulSoup(open)


Using a css selector we can get all the class names of the li:



classes_of_open_li = open_soup.select('div#tree ul.jstree-container-ul li')[0].get('class')
print(classes_of_open_li)

out: ['jstree-node', 'jstree-last', 'jstree-open']


we can then test to see whether 'jstree-open' is one of the classes:



'jstree-open' in classes_of_open_li

out: True


We can then test the opposite:



closed = '''
<div id="tree" class="jstree jstree-1">
<ul class="jstree-container-ul jstree-children">
<li class="jstree-node jstree-last jstree-closed">
</li>
</ul>
</div>
'''
closed_soup = BeautifulSoup(closed)
classes_of_closed_li = closed_soup.select('div#tree ul.jstree-container-ul li')[0].get('class')
'jstree-open' in classes_of_closed_li

out: False


After which is you wanted to select all of the list items you can use the same function to return a list of all list items:



li = '''
<div id="tree" class="jstree jstree-1">
<ul class="jstree-container-ul jstree-children">
<li class="jstree-node jstree-last jstree-closed">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</li>
</ul>
</div>
'''
line_soup = BeautifulSoup(li)
all_line_items = line_soup.select('div#tree ul.jstree-container-ul li ul li')

out: [<li></li>, <li></li>, <li></li>, <li></li>]


Hope this helps!







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 '18 at 14:36









James AndrewsJames Andrews

613




613













  • Unfortunately it doesn't work. Get some weird Errors. Will continue with my next tasks and come back later to that problem.

    – Gyrospeter
    Nov 27 '18 at 8:28



















  • Unfortunately it doesn't work. Get some weird Errors. Will continue with my next tasks and come back later to that problem.

    – Gyrospeter
    Nov 27 '18 at 8:28

















Unfortunately it doesn't work. Get some weird Errors. Will continue with my next tasks and come back later to that problem.

– Gyrospeter
Nov 27 '18 at 8:28





Unfortunately it doesn't work. Get some weird Errors. Will continue with my next tasks and come back later to that problem.

– Gyrospeter
Nov 27 '18 at 8:28




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415695%2fcheck-if-a-tree-is-expanded-or-open-selenium-python%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith