【发布时间】:2017-05-04 17:58:30
【问题描述】:
我是自动化方面的新手,我需要逐步在列表中找到人,然后转到他的个人资料并查看有关他的一些信息。当我在我的第一个 URL 上工作时,将密钥发送到搜索字段,找到我需要的人并单击完美工作。但是,当我打开家伙个人资料时,我无法使用 selenium 处理此页面上的任何元素,出现此异常,这意味着他找不到此类元素。但是当我使用 Chrome 控制台和 jQuery 时,它可以完美地找到我的元素并使用它进行操作。
> (An unhandled exception of type
> 'OpenQA.Selenium.NoSuchElementException' occurred in WebDriver.dll
> Additional information: no such element: Unable to locate element:
> {"method":"id","selector":"contentIFrame1"})
我仍然认为 webdriver 正在处理我的第一页,请提出建议。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System.Windows.Forms;
using System.Threading;
using OpenQA.Selenium.Support.UI;
namespace RLC_AccCheck_1
{
class Program
{
static void Main(string[] args)
{
using (IWebDriver driver = new ChromeDriver("c:\\Work\\Selenium"))
{
driver.Navigate().GoToUrl("URL")
driver.Manage().Window.Maximize();
Thread.Sleep(2000);
//Catherine Burke
//Console.Write("name=");
string name = "Catherine Burke";//Console.ReadLine();
IWebElement frame = driver.FindElement(By.Id("contentIFrame0"));
IWebDriver driverFrame = driver.SwitchTo().Frame(frame);
IWebElement search = driverFrame.FindElement(By.Id("crmGrid_findCriteria"));
search.SendKeys(name);
IWebElement searchImg = driverFrame.FindElement(By.Id("crmGrid_findCriteriaImg"));
searchImg.Click();
IWebElement row;
try
{
row = driverFrame.FindElement(By.CssSelector(".ms-crm-List-Data .ms-crm-List-Row:nth-child(1)"));
}
catch(NoSuchElementException)
{
Console.WriteLine(name + " is not found");
Console.ReadKey();
return;
}
IWebElement record = row.FindElement(By.CssSelector(".ms-crm-List-DataCell:nth-child(3) a"));
if (record.Text == name)
{
record.Click();
//record.GetAttribute("href")
Console.WriteLine(name + " is found");
}
else
{
Console.WriteLine(name + " is not found");
}
Thread.Sleep(3000);
String currentURL = driver.Url;
Console.WriteLine(currentURL + " is current URL ");
var windowHandles = driver.WindowHandles;
//This frame and all id/class writing below tags is not located
IWebElement frame1 = driver.FindElement(By.Id("contentIFrame1"));
IWebDriver driverFrame1 = driver.SwitchTo().Frame(frame1);
Thread.Sleep(1000);
IWebElement image = driver.FindElement(By.Id("Fax_label"));
image.Click();
//driver.SwitchTo().Frame(0);
IWebElement test = driver.FindElement(By.Id("FormSecNavigationControl-Icon"));
test.Click();
IWebElement recordType = driver.FindElement(By.CssSelector("#ddsm_recordtype .multiSel"));
Console.WriteLine(record.Text);
Console.ReadKey();
}
}
}
}
【问题讨论】:
-
新网址仍在同一窗口中
标签: c# selenium selenium-chromedriver