2016-12-19 3 views
0

私は自動化で新しく、ステップでステップごとにメンバーを見つけて、彼のプロフィールに行き、彼についての情報を確認する必要があります。私が検索フィールドにキーを送る私の最初のURLで働いているとき、私が1つ必要としている完璧な作業をする人を見つける。しかし、私は男のプロフィールを開いているとき、私はこのページ上のセレニウムを使ってこの要素を見つけることはできません。しかし、私がChrome ConsoleとjQueryを使用しているとき、それは自分の要素を見つけて、これを使って行動を起こしています。新しいURLに切り替えるSelenium /新しいURLredirectで要素を見つけることができません

> (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(); 
     } 
    } 
    } 
} 
+0

新しいURLが –

答えて

0

ユーザープロファイルページでjQueryウィンドウを使用していますか?

あなたのwebDriverがあなたの要素を含むウィンドウとは異なるウィンドウに焦点を当てている可能性があります。

これは問題がある場合は、How do I interact with a popup window with Mink, Selenium 2, and Behat?

+0

新しいURLが同じウィンドウにまだある同じウィンドウ内に残っている以前の記事を参照してください –

+0

頭に浮かぶ唯一の他の思考があなたのセレンスクリプトがしようとしたということですページの読み込みが完了する前に、ページ上の要素を検索します。不快な修正はリダイレクト後にあなたのスクリプトにsleep(xx)を伝えることですが、あなたは本質的に応答を待つ関数を書くことができます。あなたの解決策が見つかるといいですか? – Mezz

関連する問題