I am new in automatization and i need to make step by step finding guy in list, then go to his profile and check some information about him. When i am working at my first URL sending keys to Search field, finding guy that i need one and click working perfect. But when i am opening guy profile i can't adress to any element on this page using selenium, getting this exception, that meaning that he can't find such elements. But when i am using Chrome Console and jQuery it works perfectly finding my element and making actions with this.
> (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"})
I still thing that webdriver is working with my first page, and suggestions pls.
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();
}
}
}
}
Does your user profile page make use of jQuery windows?
It could be that your webDriver is focusing on a different window than the one containing your elements.
If this is the problem, see the previous post How do I interact with a popup window with Mink, Selenium 2, and Behat?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.