Search code examples
c#.netflaui

SetScrollPercent for Movies & TV with FlaUI


I'm trying to automate Movies & TV process slider enter image description here

and i tried the code below:

using System;
using System.Diagnostics;
using FlaUI.UIA3;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Process[] AllProcesslist = Process.GetProcesses();

            foreach (Process Proc in AllProcesslist)
            {
                if (!String.IsNullOrEmpty(Proc.MainWindowTitle) && Proc.MainWindowTitle == "Movies & TV")
                {
                    Console.WriteLine("Window Found!");
                    var app = new FlaUI.Core.Application(Proc);
                    using (var automation = new UIA3Automation())
                    {
                        var window = app.GetMainWindow(automation);
                        var elem = window.FindFirstDescendant(cf => cf.ByAutomationId("ProgressSlider"));
                        Console.WriteLine(elem);
                        elem.Patterns.Scroll.Pattern.SetScrollPercent(20, -1);
                    }
                }
            }

            Console.Read();
        }
    }
}

But it returns FlaUI.Core.Exceptions.PatternNotSupportedException: 'The requested pattern 'Scroll [#10004]' is not supported', I used FlaUInspect then i realized it only supports ScrollItem and RangeValue, so i change elem.Patterns.Scroll.Pattern.SetScrollPercent(20, -1) to elem.Patterns.ScrollItem.Pattern.SetScrollPercent(20, -1) but there are no SetScrollPercent for that.

how can i automate that?


Solution

  • I used RangeValue instead of ScrollItem and now it's working!

    using System;
    using System.Diagnostics;
    using FlaUI.UIA3;
    
    namespace ConsoleApp1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Process[] AllProcesslist = Process.GetProcesses();
    
                foreach (Process Proc in AllProcesslist)
                {
                    if (!String.IsNullOrEmpty(Proc.MainWindowTitle) && Proc.MainWindowTitle == "Movies & TV")
                    {
                        Console.WriteLine("Window Found!");
                        var app = new FlaUI.Core.Application(Proc);
                        using (var automation = new UIA3Automation())
                        {
                            var window = app.GetMainWindow(automation);
                            var elem = window.FindFirstDescendant(cf => cf.ByAutomationId("ProgressSlider"));
                            elem.Patterns.RangeValue.Pattern.SetValue(64);
                            Console.WriteLine(elem.Patterns.RangeValue.Pattern.Value);
                        }
                    }
                }
    
                Console.Read();
            }
        }
    }