First of all thanks for the hint,
But unfortunately I do not know exactly how I need to implement it. I hope you can help me with this?
I'm unfortunately a novice programmer
This is my current code.
Code: Select all
public void Alle_Kategorien()
{
SelectTag someSelectTag = "//div[#'ifrdiv_intranet']/iframe[@id='ifr_intranet']//frameset[#'main']/frame[@id='DVAGcontent']//div[#'searchbox']/select[@name='ebene1']";
OptionTag optTag = someSelectTag.FindSingle(".//option[@value='Bankprodukte']");
optTag.Selected = true;
optTag.Click();
}
public void Auswahl_Zeitraum()
{
SelectTag someSelectTag = "//div[#'ifrdiv_intranet']/iframe[@id='ifr_intranet']//frameset[#'main']/frame[@id='DVAGcontent']//div[#'searchbox']/select[@name='ebene2']";
OptionTag optTag = someSelectTag.FindSingle(".//option[@value='Investment']");
optTag.Selected = true;
optTag.Click();
}
And this is supposed to be the code that helps
Code: Select all
public static void SelectOption(SelectTag selectTag, OptionTag optionTag, Duration dur) {
List<string> options = GetOptionsText(selectTag);
int desiredIndex = options.IndexOf(optionTag.TagValue);
DoSelectAction(selectTag, desiredIndex, options, dur);
}
private static List<string> GetOptionsText(SelectTag selectTag) {
List<string> options = new List<string>();
foreach (OptionTag ot in selectTag.Find<OptionTag>(".//option")) {
options.Add(ot.TagValue != null ? ot.TagValue : "");
}
return options;
}
private static void DoSelectAction(SelectTag selectTag, int desiredIndex, List<string> options, Duration dur) {
int selectedIndex = 0;
if (selectTag.TagValue != null) {
List<OptionTag> optiontags = new List<OptionTag>(selectTag.Find<OptionTag>(".//optiontag[@TagValue='" + selectTag.TagValue + "']"));
if (options.Count > 0) {
OptionTag selectedOptionTag = optiontags[0];
selectedIndex = options.IndexOf(selectedOptionTag.TagValue);
}
}
Keyboard.PrepareFocus(selectTag);
Duration oldKeyPressTime = Keyboard.DefaultKeyPressTime;
Keyboard.DefaultKeyPressTime = 15;
Duration keyPressDuration = dur;
if (desiredIndex < selectedIndex) {
for (int i = desiredIndex; i < selectedIndex; i++) {
//up
Report.Log(ReportLevel.Info, "Keyboard", "Key 'Up' Press with focus on '" + selectTag.GetPath() + "'.");
Keyboard.Press(System.Windows.Forms.Keys.Up, Keyboard.DefaultScanCode, keyPressDuration, 1, true);//Keyboard.DefaultKeyPressTime, 1, true);
}
} else if (selectedIndex < desiredIndex) {
for (int i = selectedIndex; i < desiredIndex; i++) {
//down
Report.Log(ReportLevel.Info, "Keyboard", "Key 'Down' Press with focus on '" + selectTag.GetPath() + "'.");
Keyboard.Press(System.Windows.Forms.Keys.Down, Keyboard.DefaultScanCode, keyPressDuration, 1, true);//Keyboard.DefaultKeyPressTime, 1, true);
}
}
Report.Log(ReportLevel.Info, "Keyboard", "Key 'Enter' Press with focus on '" + selectTag.GetPath() + "'.");
Keyboard.Press(System.Windows.Forms.Keys.Enter, Keyboard.DefaultScanCode, keyPressDuration, 1, true);//Keyboard.DefaultKeyPressTime, 1, true);
Keyboard.DefaultKeyPressTime = oldKeyPressTime;
}
Unfortunately, I do not know how I can implement the code with my existing code. I hope you could help me.