我将一些来自Selenium IDE的代码导出到Visual Studio 2013中的C#页面,它不断给我这个错误。我只是将导出文档中的步骤复制到我的c#页面中。平台在实际页面上找到LinkText,但它一直给我这个错误。 我改变它以通过id找到元素,但是,我不知道如何在网页中选择菜单项。 我非常感谢你对此的帮助。 谢谢
我收到此错误:
{"无法找到元素:{\"方法\":\"链接文字\",\"选择器\" :\"我的简历\"}"} **
这是我的代码:
:
答案 0 :(得分:2)
您必须先将鼠标悬停在菜单项"关于我"之前 点击子菜单项"我的简历"。你也可以使用Selenium的Actions命令。
我对C#不太了解,但你的代码会是这样的:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Interactions;
namespace MyFirstAutoScript
{
class Program
{
static void Main(string[] args)
{
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("https://yelitzascareerjourney.wordpress.com/");
new Actions(driver).MoveToElement(driver.FindElement(By.LinkText("About Me"))).Click().Build().Perform();
driver.FindElement(By.LinkText("My Resume")).Click(); //my page brakes here
more commands go here...
}
}
}
我曾使用
new Actions(driver).MoveToElement(driver.FindElement(By.LinkText("About Me"))).Click().Build().Perform();
鼠标悬停在菜单项上。