I am trying to create a WebElement
object. I saw that there is a IWebElement
interface which i could implement.
I also saw this question and did't manage to implement it sucessfully.
In my usecase I get from a webpage all forms and then take the one with the most input
tags which haven't got the type
attribute set to hidden
.
this is my usecase code:
using System;
using System.Linq;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace AutoWinner
{
class Program
{
static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver();
driver.Url = "https://keepass.info/help/kb/testform.html";
var forms = driver.FindElements(By.TagName("form"));
var longestFormLengthOfAllForms = 0;
// I don't the p element.
// It's more here to just get a webElement which ic can later overwrite.
var mainForm = driver.FindElement(By.TagName("p"));
foreach (var form in forms)
{
Console.WriteLine(form.GetAttribute("outerHTML"));
var children = form.FindElements(By.TagName("input"));
var lengthOfCurrentForm = children.Count(x => x.GetAttribute("type") != "hidden");
if (lengthOfCurrentForm > longestFormLengthOfAllForms)
{
longestFormLengthOfAllForms = lengthOfCurrentForm;
mainForm = form;
}
}
Console.WriteLine(mainForm.GetAttribute("outerHTML"));
}
}
}
The line var mainForm = driver.FindElement(By.TagName("p"));
is meant to be a global variable where later save my main form in it. I don't need the p
element.
my Idea was to remove by creating a standard webElement
.
How could i get rid of it or improve it?