本文整理汇总了C#中Actions.MoveToElement方法的典型用法代码示例。如果您正苦于以下问题:C# Actions.MoveToElement方法的具体用法?C# Actions.MoveToElement怎么用?C# Actions.MoveToElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Actions
的用法示例。
在下文中一共展示了Actions.MoveToElement方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GeneralTestingBaidu
//.........这里部分代码省略.........
//{
// Assert.Fail();
//}
selenium.Type("id=TANGRAM__PSP_8__userName", "13764393095");
selenium.Type("id=TANGRAM__PSP_8__password", "edGomvS1");
selenium.Click("id=TANGRAM__PSP_8__submit");
selenium.WaitForPageToLoad("30000");
//if (selenium.IsTextPresent("密码错误"))
//{
// Assert.Fail();
//}
selenium.Click("link=退出");
selenium.Click("link=确定");
selenium.WaitForPageToLoad("30000");
//测试搜索
selenium.Type("kw", "Selenium");
selenium.Click("su");
selenium.WaitForPageToLoad("30000");
Assert.IsTrue(selenium.IsTextPresent("硒"));
}
catch (Exception e)
{
}
finally
{
selenium.Close();
selenium.Stop();
}
}
else
{
try
{
//测试主页被打开
driver.Manage().Window.Maximize();
navigation = driver.Navigate();
navigation.GoToUrl(tagetURL);
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
actualTitle = driver.Title;
StringAssert.Equals(actualTitle, "百度一下,你就知道");
//测试糯米链接
driver.FindElementByLinkText("糯米").Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
actualTitle = driver.Title;
StringAssert.Equals(actualTitle, "【上海团购】上海团购网站,高品质团购网站-百度糯米");
navigation.Back();
//测试新闻链接
driver.FindElementByLinkText("新闻").Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
actualTitle = driver.Title;
StringAssert.Equals(actualTitle, "百度新闻搜索——全球最大的中文新闻平台");
navigation.Back();
//测试登陆
driver.FindElementByLinkText("登录").Click();
//if (!selenium.IsTextPresent("登录百度账号"))
//{
// Assert.Fail();
//}
IWebElement webElement = driver.FindElementById("TANGRAM__PSP_8__userName");
webElement.SendKeys("13764393095");
webElement = driver.FindElementById("TANGRAM__PSP_8__password");
webElement.SendKeys("edGomvS1");
driver.FindElementById("TANGRAM__PSP_8__submit").Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
//if (selenium.IsTextPresent("密码错误"))
//{
// Assert.Fail();
//}
Actions mouseMove = new Actions(driver);
webElement = driver.FindElementByClassName("user-name");
mouseMove.MoveToElement(webElement);
mouseMove.Perform();
webElement = driver.FindElementByClassName("quit");
webElement.Click();
driver.FindElementByLinkText("确定").Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
//测试搜索
webElement = driver.FindElementById("kw");
webElement.SendKeys("Selenium");
driver.FindElementById("su").Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
Assert.IsTrue(driver.FindElements(By.XPath("//*[contains(text(),'硒')]")).Count > 0);
}
catch (Exception e)
{
}
finally
{
driver.Quit();
}
}
}
示例2: RightClick
/// <summary>
/// Right click an item in within the current document.
/// </summary>
/// <param name="driver"></param>
/// <param name="oWE">An item within the current document.</param>
public static void RightClick(this IWebDriver driver, IWebElement oWE)
{
Actions oAction = new Actions(driver);
oAction.MoveToElement(oWE);
oAction.ContextClick(oWE).Build().Perform();
}
示例3: vfyTooltip
public void vfyTooltip(tstObject tstObj, string tblPath, ref string[,] rsltArray, out int fndExcep, out int tstFail)
{
bool objPres;
string clkPath;
string tempstring;
string vfyString;
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
Actions builder = new Actions(driver);
IWebElement thsObj;
fndExcep = 0;
tstFail = 0;
try
{
tempstring = tblPath.Substring(1, tblPath.Length - 4);
clkPath = tempstring + "[2]";
driver.FindElement(By.XPath(clkPath)).Click();
//strip off the last
//set theObj to the object the tooltip is in
thsObj = (IWebElement)driver.FindElement(By.XPath(tblPath));
//move the app to the tooltip object
Actions hoverOverTooltip = builder.MoveToElement(thsObj);
//perform the hover
hoverOverTooltip.Perform();
vfyString = driver.FindElement(By.XPath(tblPath)).GetAttribute("onmouseover");
}
catch(Exception e)
{
objPres = false;
//add string to the test results list
tmpString = e.Message;
rsltArray = arrayAppend(objPres.ToString(), tmpString, "-1", String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, rsltArray);
fndExcep = -1;
}
}
示例4: MouseHover
//Mouse Hover
public void MouseHover(String locator)
{
this.WaitForElementPresent(locator, 20);
Boolean x = isElementPresent(locator);
Assert.IsTrue(isElementPresent(locator));
IWebElement el = driver.FindElement(ByLocator(locator));
Actions builder = new Actions(driver);
builder.MoveToElement(el).Perform();
}
示例5: DoWork
public void DoWork()
{
driver.Url = "http://luotbao.com";
//wait load
driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0,1,0));
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
//find "dunghiennua" element
element = driver.FindElement(By.Id("fancybox-close"));
element.Click();
//find "kinhte" element
//tao vong lap for cho viec lap lai type:
//di tu 1 den 12
//element = driver.FindElement(By.CssSelector("ul>li:nth-of-type(7)>a"));
for (int i = 1; i < 11; i++ )
{
string css = "ul>li:nth-of-type("+ i+ ")>a";
Console.WriteLine(css);
element = driver.FindElement(By.CssSelector(css));
//Lấy danh sách tin (5 tin) trong muc "kinh te"
//chua su dung scroll
IList<IWebElement> article_elements = driver.FindElements(By.CssSelector("a[href^='http://luotbao.com/index.php/pages/article']"));
//kiem tra su ton tai cua phan tu vua tim
if (article_elements != null && article_elements.Count > 0)
{
//Chạy từng bài báo
foreach (IWebElement article_ele in article_elements)
{
string url = article_ele.GetAttribute("href");
//dung javascript mo 1 cua so moi
IJavaScriptExecutor jscript = driver as IJavaScriptExecutor;
jscript.ExecuteScript("window.open()");
//nhay vao cua so cuoi cung.
List<string> handles = driver.WindowHandles.ToList<string>();
driver.SwitchTo().Window(handles.Last());
//dan dia chi url vao.
driver.Navigate().GoToUrl(url);
//Lấy link nút Like của facebook trên bài báo
//tim frame cong nge
IList<IWebElement> frames;
IWebElement tieudeh4 = driver.FindElement(By.CssSelector("h4.title"));
string chuoi = tieudeh4.Text;
string comment = "Chia sẻ: " + chuoi;
Console.WriteLine(comment);
try
{
//tim frame facebook
frames = driver.FindElements(By.CssSelector("div.fblikebutton>iframe[src^='http://www.facebook.com/plugins/like.php?href=http://luotbao.com/index.php/pages/article']"));
}
catch
{
//tim khong thay frame facebook, thi dong cua so window.
//nhay vao cua so cuoi cung.
driver.SwitchTo().Window(handles.Last());
jscript.ExecuteScript("window.close()");
//nhay vao trang danh sach.
handles = driver.WindowHandles.ToList<string>();
driver.SwitchTo().Window(handles.Last());
continue;
}
//neu frame ton tai thi nhay vao
if (frames.Count > 0)
{
//nhay vao frame
//string link_likeFacebook = frames[0].GetAttribute("src"); ;
driver.SwitchTo().Frame(frames[0]);
driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 1, 0));
//neu nut like book o trang thai like button thi thoat
//try
//{
//tim phan tu nut like o 2 trang thai
IWebElement like_button_no_like = driver.FindElement(By.CssSelector("a[class^='connect_widget_like_button clearfix']"));
if (like_button_no_like.GetAttribute("class").Contains("like_button_no_like"))
{
//kiem tra neu chua thich thi click thich
like_button_no_like.Click();
//chú ý: con chuot trên màn hình, khi mouseover phai đem ra ngoài khu vực cửa sổ mới mở.
Thread.Sleep(1000);
IWebElement likebuttonlike = driver.FindElement(By.CssSelector("a[class='connect_widget_like_button clearfix like_button_like']"));
Actions builer = new Actions(driver);
builer.MoveToElement(likebuttonlike).Build().Perform();
//click chuot vao nut like_button_like de xuat hien commment
likebuttonlike.Click();
IWebElement element_comment = driver.FindElement(By.CssSelector("table.uiGrid td:first-of-type > input"));
//.........这里部分代码省略.........