我正在使用Watin,我想運行一些自定義JavaScript。我無法使用Browser.Eval,因爲有時我會想要在IFrame內執行代碼。我曾嘗試使用DomContainer屬性,但DomContainer返回完整的DOM而不是IFrame的DOM。 下例:當元素位於IFrame中時,是否可以讓DomContainer返回Iframe?
Element.DomContainer.Eval(jScript)
有沒有辦法做到這一點使用Element對象?
我想避免有兩個構造函數。 (見下文):
public class TelerikWatinTextBox: ITextBox
{
public TelerikWatinTextBox(Frame frame, string clientId)
{
Frame = frame;
ClientId = clientId;
}
public TelerikWatinTextBox(Browser browser, string clientId)
{
Browser = browser;
ClientId = clientId;
}
public string ClientId { get; set; }
public Browser Browser { get; set; }
public Frame Frame { get; set; }
#region ITextBox Members
public string Value
{
get
{
string value = "";
string jScript = string.Format(@"$find(""{0}"").get_value();", ClientId);
if (Browser != null)
{
value = Browser.Eval(jScript);
}
else if (Frame != null)
{
value = Frame.Eval(jScript);
}
return value;
}
set
{
string jScript = string.Format(@"$find(""{0}"").set_value(""{1}"");", ClientId, value);
if (Browser != null)
{
Browser.Eval(jScript);
}
else if (Frame != null)
{
Frame.Eval(jScript);
}
}
}
#endregion
}
public interface ITextBox
{
string Value { get; set; }
}
N.B. clientId是對DIV的引用。
你能更好地解釋您的需求?例如,爲什麼不能區分第一種情況下調用Browser.Eval和第二種情況下調用Browser.Frames [x] .Eval(jScript)的兩種情況? – Gabber 2012-03-21 13:41:47
我的網頁中有telerik控件,使用watin與它們進行交互的最佳方式是執行一些javascript。它不像檢查Input元素那麼簡單。例如,我有一個接口ITextBox。如果它的telerik文本框,然後我運行JS。如果它是一個標準輸入元素,我只需設置該值。運行JS我需要找到ITextBox的DOM容器。有時這是一個框架,其他時候是瀏覽器。 – 2012-03-22 15:30:12
你對你正在尋找的元素有什麼樣的信息?你知道它是ITextBox類型的元素嗎?如果你可以提取它的ID,你可以識別它的祖先以最終識別包含的幀(或者如果沒有包含幀的文件) – Gabber 2012-03-22 16:00:25