1

わかりました、これは簡単なことのように思えますが、方法がわかりません。パックを使用しhtmlagilityて Web ページを解析しましたが、うまく機能します。さて、問題は以下です。

<td width="45%" class="TextBold" nowrap>
<select name="ctl00$BodyContent$ddlChooseView" onchange="if (this.selectedIndex > 0
{pageTracker._trackEvent('webpage tracker','complete report',this.options
[this.selectedIndex].text);}
ShowProcessing(this);setTimeout('__doPostBack(\'ctl00$BodyContent$ddlChooseView\',\'\')', 
    0)" id="ctl00_BodyContent_ddlChooseView" class="TextBold">
        <option selected="selected" value=""> -- Select a view -- </option>
        <option value="H">Option1</option>
        <option value="R">Option2</option>
        <option value="N">Option3</option>
        <option value="NA">Option4</option>
        <option value="RN">Option5</option>
        <option value="QP">Option6</option>

</select>
</td>

これが正しくフォーマットされていない場合は、申し訳ありません。htmlそして、選択オブジェクトのオプションの1つを選択したいと思います。ページで新しい表示をトリガーし、その「新しい」Web ページを解析します。これはできhtmlagilitypackますか?そうでない場合、オプションの 1 つを選択するにはどうすればよいですか?

4

3 に答える 3

0

このコードはあなたに役立つかもしれませんそれは基本的な詳細を含んでいます。

<code>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

//Need to add these two libarary
//For that u need to have WebDriver.dll and WebDriver.Support.dll 
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;

namespace Test
{
class Program
{
static void Main(string[] args)
{
//Intializing the webdriver. 
//Note i m using firefox driver, others can also be used.
IWebDriver driver = new OpenQA.Selenium.Firefox.FirefoxDriver();
//Navigating to the given page.
driver.Navigate().GoToUrl("url of the page you want to get the option from");
//Finding the element. If element not present it throws exception so do remember to handle it.
var element = driver.FindElement(By.Id("ctl00_BodyContent_ddlChooseView"));
//No intializing the select element option.
SelectElement selectElem = new SelectElement(element);
selectElem.SelectByValue("H"); 
//or i can select option using text that is
selectElem.SelectByText("Option1"); 
}

}
}
</code>

インデントでごめんなさい。

于 2013-02-23T04:35:23.437 に答える
0

HtmlAgilityPackができるのか少し混乱していると思います...

HtmlAgilityPack- 単なるプラサーです。

からbrowser's point of view、オプションの 1 つを選択すると、ブラウザはPOSTタイプ リクエストをページに送信します。

今できることは、または を使用してそのPOSTリクエストをシミュレートすることです。そうすれば、を使用してその新しい WebPage で作業できるようになります。WebClientHttpWebRequestnew web pageHtmlAgilityPack

于 2013-02-23T03:42:02.800 に答える
0

これは、selenium webdriver を使用して簡単に実行できます。この種のものを処理するのに適しています。

ここでは、最初に Webdriver ライブラリを使用してオプションを取得した要素を選択します
var selectElem = driver.FindElement(By.Id("ctl00_BodyContent_ddlChooseView"));

今 WebDriver.Support.UI ライブラリを使用して、すべてのオプションを取得します
SelectElement selectOption = new SelectElement(selectElem);

これで、要素に対して任意のアクションを実行できます。つまり
、好き
selectOption.SelectByValue("here u give the value")

selectOption.SelectByText("here u give the value")

などなど、あなたが発見したことはたくさんあります。

于 2013-02-23T03:42:28.880 に答える