Jak to wygląda w selenium
var IDriver = new IWebDriver(); // jakoś tak bo definiujemy tutaj przeglądarkę
odwołanie do pobierania elementu wygląda coś podobnego chciał bym stworzyć
IWebElement element = IDriver.FindElement(By.Id(serchValue)); // zwraca element
List<IWebElement> elements = IDriver.FindElements(By.Id(serchValue));
Tak wygląda interface FindElement
public interface ISearchContext
{
IWebElement FindElement(By by);
ReadOnlyCollection<IWebElement> FindElements(By by);
}
A tak wygląda konstrukcja By który jest bardziej rozbudowany niż myślałem ;) Nie wiem co oznacza [Serializable] ;) oraz dla czego jest to tak zbudowane do większości niestety nie mam podglądu
[Serializable]
public class By
{
protected By();
protected By(Func<ISearchContext, IWebElement> findElementMethod, Func<ISearchContext, ReadOnlyCollection<IWebElement>> findElementsMethod);
public static bool operator !=(By one, By two);
public static bool operator ==(By one, By two);
protected string Description { get; set; }
protected Func<ISearchContext, IWebElement> FindElementMethod { get; set; }
protected Func<ISearchContext, ReadOnlyCollection<IWebElement>> FindElementsMethod { get; set; }
public static By ClassName(string classNameToFind);
public static By CssSelector(string cssSelectorToFind);
public override bool Equals(object obj);
public virtual IWebElement FindElement(ISearchContext context);
public virtual ReadOnlyCollection<IWebElement> FindElements(ISearchContext context);
public override int GetHashCode();
public static By Id(string idToFind);
public static By LinkText(string linkTextToFind);
public static By Name(string nameToFind);
public static By PartialLinkText(string partialLinkTextToFind);
public static By TagName(string tagNameToFind);
public override string ToString();
public static By XPath(string xpathToFind);
}
Tak mniej więcej wygląda to co jest zwracane
Defakto ja tego nie potrzebuje bo tak naprawdę nie działam na żywym elemencie tylko przechowuje w nim dane nic więcej.
public interface IWebElement : ISearchContext
{
bool Displayed { get; }
bool Enabled { get; }
System.Drawing.Point Location { get; }
bool Selected { get; }
System.Drawing.Size Size { get; }
string TagName { get; }
string Text { get; }
void Clear();
void Click();
string GetAttribute(string attributeName);
string GetCssValue(string propertyName);
void SendKeys(string text);
void Submit();
}
Natomiast tak wygląda Budowa samego Drivera
public class RemoteWebDriver : IWebDriver, IDisposable, ISearchContext, IJavaScriptExecutor, IFindsById, IFindsByClassName, IFindsByLinkText, IFindsByName, IFindsByTagName, IFindsByXPath, IFindsByPartialLinkText, IFindsByCssSelector, ITakesScreenshot, IHasInputDevices, IHasCapabilities, IHasWebStorage, IHasLocationContext, IHasApplicationCache, IAllowsFileDetection, IHasSessionId
{
protected static readonly TimeSpan DefaultCommandTimeout;
public RemoteWebDriver(ICapabilities desiredCapabilities);
public RemoteWebDriver(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities);
public RemoteWebDriver(Uri remoteAddress, ICapabilities desiredCapabilities);
public RemoteWebDriver(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan commandTimeout);
public IApplicationCache ApplicationCache { get; }
public ICapabilities Capabilities { get; }
protected ICommandExecutor CommandExecutor { get; }
public string CurrentWindowHandle { get; }
public virtual IFileDetector FileDetector { get; set; }
public bool HasApplicationCache { get; }
public bool HasLocationContext { get; }
public bool HasWebStorage { get; }
public IKeyboard Keyboard { get; }
public ILocationContext LocationContext { get; }
public IMouse Mouse { get; }
public string PageSource { get; }
public SessionId SessionId { get; }
public string Title { get; }
public string Url { get; set; }
public IWebStorage WebStorage { get; }
public ReadOnlyCollection<string> WindowHandles { get; }
public void Close();
protected virtual RemoteWebElement CreateElement(string elementId);
public void Dispose();
protected virtual void Dispose(bool disposing);
protected virtual Response Execute(string driverCommandToExecute, Dictionary<string, object> parameters);
public object ExecuteAsyncScript(string script, params object[] args);
public object ExecuteScript(string script, params object[] args);
protected object ExecuteScriptCommand(string script, string commandName, params object[] args);
public IWebElement FindElement(By by);
protected IWebElement FindElement(string mechanism, string value);
public IWebElement FindElementByClassName(string className);
public IWebElement FindElementByCssSelector(string cssSelector);
public IWebElement FindElementById(string id);
public IWebElement FindElementByLinkText(string linkText);
public IWebElement FindElementByName(string name);
public IWebElement FindElementByPartialLinkText(string partialLinkText);
public IWebElement FindElementByTagName(string tagName);
public IWebElement FindElementByXPath(string xpath);
public ReadOnlyCollection<IWebElement> FindElements(By by);
protected ReadOnlyCollection<IWebElement> FindElements(string mechanism, string value);
public ReadOnlyCollection<IWebElement> FindElementsByClassName(string className);
public ReadOnlyCollection<IWebElement> FindElementsByCssSelector(string cssSelector);
public ReadOnlyCollection<IWebElement> FindElementsById(string id);
public ReadOnlyCollection<IWebElement> FindElementsByLinkText(string linkText);
public ReadOnlyCollection<IWebElement> FindElementsByName(string name);
public ReadOnlyCollection<IWebElement> FindElementsByPartialLinkText(string partialLinkText);
public ReadOnlyCollection<IWebElement> FindElementsByTagName(string tagName);
public ReadOnlyCollection<IWebElement> FindElementsByXPath(string xpath);
public Screenshot GetScreenshot();
public IOptions Manage();
public INavigation Navigate();
public void Quit();
protected virtual void StartClient();
protected void StartSession(ICapabilities desiredCapabilities);
protected virtual void StopClient();
public ITargetLocator SwitchTo();
}
Gdzie to mnie najbardziej interesuje
// Dla pojedyńczego elementu
public IWebElement FindElement(By by);
protected IWebElement FindElement(string mechanism, string value);
public IWebElement FindElementByClassName(string className);
public IWebElement FindElementByCssSelector(string cssSelector);
public IWebElement FindElementById(string id);
public IWebElement FindElementByLinkText(string linkText);
public IWebElement FindElementByName(string name);
public IWebElement FindElementByPartialLinkText(string partialLinkText);
public IWebElement FindElementByTagName(string tagName);
public IWebElement FindElementByXPath(string xpath);
// Dla list
public ReadOnlyCollection<IWebElement> FindElements(By by);
protected ReadOnlyCollection<IWebElement> FindElements(string mechanism, string value);
public ReadOnlyCollection<IWebElement> FindElementsByClassName(string className);
public ReadOnlyCollection<IWebElement> FindElementsByCssSelector(string cssSelector);
public ReadOnlyCollection<IWebElement> FindElementsById(string id);
public ReadOnlyCollection<IWebElement> FindElementsByLinkText(string linkText);
public ReadOnlyCollection<IWebElement> FindElementsByName(string name);
public ReadOnlyCollection<IWebElement> FindElementsByPartialLinkText(string partialLinkText);
public ReadOnlyCollection<IWebElement> FindElementsByTagName(string tagName);
public ReadOnlyCollection<IWebElement> FindElementsByXPath(string xpath);
a tak wygląda IWebDriver
string CurrentWindowHandle { get; }
string PageSource { get; }
string Title { get; }
string Url { get; set; }
ReadOnlyCollection<string> WindowHandles { get; }
void Close();
IOptions Manage();
INavigation Navigate();
void Quit();
ITargetLocator SwitchTo();
Był bym wdzięczny jak ktoś by mi pomógł to zrozumieć oraz posklecać pod siebie ;)