2017-11-01 2 views
0

私はセレニウムも何も使用していません.WindowsフォームアプリケーションのWebブラウザでのみ行います。 私はWindowsフォームアプリケーションを持っていますが、コード付きのボタンをクリックしたいのですが、IDはありません。C#IDなしのHtmlElementをクリックしてください。クラス

Here

私はこのウェブサイトのフォーラムで見られる異なる多くのものを使用してみましたが、これのどれも機能しません。

This is what i work with

+0

あなたの写真のHTMLに表示されるHTMLには、フォームはありません。 –

+0

私は、フォームウィンドウのフォームアプリケーションを申し訳ありません申し訳ありません – n0degg

答えて

0

あなたが提出= WebBrowser.GetElementByTagName( "DIV")を使用して、その後、属性タイプに対して各要素をチェックしようとしたことがありますか? あなたのコードはMSDN docsにGetElementsByTagNameメソッドの詳細

HtmlElement submit = FindSubmitElement(webBrowser1.Document); 
submit?.InvokeMember("submit"); 

public HtmlElement FindSubmitElement(HtmlDocument document) 
{ 
    HtmlElementCollection elems = document.GetElementsByTagName("div"); // since your tag is div 
    // this will return collection, even in case there is just one div, find the first one, having an attribute 'type' with value 'submit' 
    foreach (HtmlElement elem in elems) 
    { 
     string type = elem.GetAttribute("type"); 
     if (!string.IsNullOrEmpty(type) && type == "submit") 
     { 
      return elem; // if div tag with attribute type is found exit and return that html element 
     } 
    } 

    return null; // if no div tags found with an attribute 'type' return null 
} 

チェックのようになります。コードはそこから取得され、必要に応じて調整されます。

+1

それは最初に動作しませんでしたが、私はInvokeMemberをクリックして送信し、それはうまく働いた、感謝:D – n0degg

関連する問題