web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Conditional Data extra...
Power Automate
Answered

Conditional Data extraction from Web page

(0) ShareShare
ReportReport
Posted on by 29

Hi All,
I am stuck with a issue with extracting data on webpage. Any help is appreciated.

 

this is my HTML:

<ul class="list">

     <li class="list item">

            <svg  visibility: visible;</svg>
            <Span class= "target">text</span>

     </li>

   <li class="list item">

            <svg  visibility: hidden;</svg>
            <Span class= "target">text</span>

     </li>

</ul>

I want to extract the target span text if only the svg visibility class is = Visible. if hidden I don't want to extract it.

Thanks

best
Mohd

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @mohammed_24 

     

    Is your website/web application comprised of only two <li> elements, or are there multiple? If there are multiple <li> elements present, would you like to extract the text from all <span> elements where the corresponding <svg> has a visibility value?

     

     

  • mohammed_24 Profile Picture
    29 on at

    Yes there are multiple list items and yes I want to extract every span content if svg is visible.

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @mohammed_24 

     

    Please try the below JavaScript for the same:

    Deenuji_0-1716740172082.png

     

     

    Javascript

     

    function ExecuteScript() {
    // Initialize an empty array to store the text content values
    let textContentList = [];
    
    // Select all list items
    const listItems = document.querySelectorAll('.list-item');
    
    // Iterate over each list item
    listItems.forEach(item => {
     // Select the svg element inside the current list item
     const svgElement = item.querySelector('svg');
     // Check if the visibility attribute of the svg element is 'visible'
     if (svgElement && svgElement.style.visibility === 'visible') {
     // Select the span element with class 'target' inside the current list item
     const spanElement = item.querySelector('.target');
     // Extract and append the text content of the span element to the list
     if (spanElement) {
     const textContent = spanElement.textContent.trim();
     textContentList.push(textContent);
     }
     }
    });
    
    // Return the list of text content values
    const resultString = textContentList.join(', ');
    
    return resultString;
    
    
    }

     

     

    Full flow:

    Deenuji_1-1716740324024.png

     

    Full flow code:

    WebAutomation.LaunchChrome.LaunchChrome Url: $'''https://peaceful-hippopotamus.static.domains/testapp''' WindowState: WebAutomation.BrowserWindowState.Maximized ClearCache: False ClearCookies: False WaitForPageToLoadTimeout: 60 Timeout: 60 PiPUserDataFolderMode: WebAutomation.PiPUserDataFolderModeEnum.AutomaticProfile BrowserInstance=> Browser
    WebAutomation.ExecuteJavascript BrowserInstance: Browser Javascript&colon; $'''function ExecuteScript() {
    // Initialize an empty array to store the text content values
    let textContentList = [];
    
    // Select all list items
    const listItems = document.querySelectorAll(\'.list-item\');
    
    // Iterate over each list item
    listItems.forEach(item => {
     // Select the svg element inside the current list item
     const svgElement = item.querySelector(\'svg\');
     // Check if the visibility attribute of the svg element is \'visible\'
     if (svgElement && svgElement.style.visibility === \'visible\') {
     // Select the span element with class \'target\' inside the current list item
     const spanElement = item.querySelector(\'.target\');
     // Extract and append the text content of the span element to the list
     if (spanElement) {
     const textContent = spanElement.textContent.trim();
     textContentList.push(textContent);
     }
     }
    });
    
    // Return the list of text content values
    const resultString = textContentList.join(\', \');
    
    return resultString;
    
    
    }''' Result=> Result

    Once you get results with comma delimiter use split power automate function and convert your results into list.

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

  • mohammed_24 Profile Picture
    29 on at

    I don't get any output.

    I just noticed that the span itself-
    if the svg is visible span text has style attribute which has "color: var(--color-black);"

    can we use this??
    normally, without JS?

     

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @mohammed_24 

     

    Please share your exact source code of your li elements.

     

     

  • mohammed_24 Profile Picture
    29 on at

    mohammed_24_0-1716791420473.png

    here

     

  • mohammed_24 Profile Picture
    29 on at

    i have to extract span content where - style is color: var(--color-black)

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @mohammed_24 

     

    So you don't want to extract based on svg visibility?

  • mohammed_24 Profile Picture
    29 on at

    Yes Apologies  ; I found out the style attribute from which, I think it would be easier to extract the span content.

     

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @mohammed_24 
    But from the above sample html code even svg visibility is hidden all span css style is tagged with color: var(--color-black). So you want all the text from the above sample?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 432

#2
11manish Profile Picture

11manish 313 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 154

Last 30 days Overall leaderboard