亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

Selenium API(C#)

系統 2968 0

?

1 Fetching a Page

?

driver . Url ? = ? "http://www.google.com" ;

?

2 Locating UI Elements (WebElements)

?

By ID

?

This is the most efficient and preferred way to locate an element. Common pitfalls that UI developers make is having non-unique id’s on a page or auto-generating the id, both should be avoided. A class on an html element is more appropriate than an auto-generated id.

?

Example of how to find an element that looks like this:

?

        
          <div
        
        
          id=
        
        
          "coolestWidgetEvah"
        
        
          >
        
        ...
        
          </div>
        
      

?

IWebElement ? element ? = ? driver . FindElement ( By . Id ( "coolestWidgetEvah" ));

?

?

?

By Class Name

?

“Class” in this case refers to the attribute on the DOM element. Often in practical use there are many DOM elements with the same class name, thus finding multiple elements becomes the more practical option over finding the first element.

?

Example of how to find an element that looks like this:

?

<div ? class= "cheese" ><span> Cheddar </span></div><div ? class= "cheese" ><span> Gouda </span></div>

?

IList < IWebElement > ? cheeses ? = ? driver . FindElements ( By . ClassName ( "cheese" ));

?

?

?

By Tag Name

?

The DOM Tag Name of the element.

?

Example of how to find an element that looks like this:

?

        
          <iframe
        
        
          src=
        
        
          "..."
        
        
          ></iframe>
        
        
IWebElement frame = driver . FindElement ( By . TagName ( "iframe" ));

By Link Text

Find the link element with matching visible text.

Example of how to find an element that looks like this:

            
              <a
            
            
              href=
            
            
              "http://www.google.com/search?q=cheese"
            
            
              >
            
            cheese
            
              </a>
            
            
IWebElement cheese = driver . FindElement ( By . LinkText ( "cheese" ));

By CSS

Like the name implies it is a locator strategy by css. Native browser support is used by default, so please refer to? w3c css selectors <http://www.w3.org/TR/CSS/#selectors> for a list of generally available css selectors. If a browser does not have native support for css queries, then? Sizzle ?is used. IE 6,7 and FF3.0 currently use Sizzle as the css query engine.

Beware that not all browsers were created equal, some css that might work in one version may not work in another.

Example of to find the cheese below:

                
                  <div
                
                
                  id=
                
                
                  "food"
                
                
                  ><span
                
                
                  class=
                
                
                  "dairy"
                
                
                  >
                
                milk
                
                  </span><span
                
                
                  class=
                
                
                  "dairy aged"
                
                
                  >
                
                cheese
                
                  </span
                
                
IWebElement cheese = driver . FindElement ( By . CssSelector ( "#food span.dairy.aged" ));

By XPATH

At a high level, WebDriver uses a browser’s native XPath capabilities wherever possible. On those browsers that don’t have native XPath support, we have provided our own implementation. This can lead to some unexpected behaviour unless you are aware of the differences in the various xpath engines.

Driver Tag and Attribute Name Attribute Values Native XPath Support
HtmlUnit Driver Lower-cased As they appear in the HTML Yes
Internet Explorer Driver Lower-cased As they appear in the HTML No
Firefox Driver Case insensitive As they appear in the HTML Yes

This is a little abstract, so for the following piece of HTML:

                    
                      <input
                    
                    
                      type=
                    
                    
                      "text"
                    
                    
                      name=
                    
                    
                      "example"
                    
                    
                      />
                    
                    
                      <INPUT
                    
                    
                      type=
                    
                    
                      "text"
                    
                    
                      name=
                    
                    
                      "other"
                    
                    
                      />
                    
                  
                
                  
                    IList
                  
                  
                    <
                  
                  
                    IWebElement
                  
                  
                    >
                  
                  
                    inputs
                  
                  
                    =
                  
                  
                    driver
                  
                  
                    .
                  
                  
                    FindElements
                  
                  
                    (
                  
                  
                    By
                  
                  
                    .
                  
                  
                    XPath
                  
                  
                    (
                  
                  
                    "http://input"
                  
                  
                    ));
                  
                
              

Using JavaScript

You can execute arbitrary javascript to find an element and as long as you return a DOM Element, it will be automatically converted to a WebElement object.

Simple example on a page that has jQuery loaded:

                ?
              
                    
                      
                        IWebElement
                      
                      
                        element
                      
                      
                        =
                      
                      
                        (
                      
                      
                        IWebElement
                      
                      
                        )
                      
                      
                        ((
                      
                      
                        IJavaScriptExecutor
                      
                      
                        )
                      
                      
                        driver
                      
                      
                        ).
                        
                          ExecuteScript
                        
                        
                          (
                        
                        
                          "return $('.cheese')[0]"
                        
                        
                          );
                        
                      
                    
                  

?

Selenium API(C#)


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲视频网站在线观看 | 在线91精品亚洲网站精品成人 | 99精品全国免费7观看视频 | 久草在线视频资源站 | 我想看一级播放片一级的 | 日本欧美韩国专区 | 99国产在线播放 | 国产精品社区在线观看 | 婷婷成人综合 | 欧美日韩大尺码免费专区 | 久久99热成人精品国产 | 一级大片免费观看 | 欧美xxxxbbbb在线播放 | 亚洲国产第一区 | 日本不卡中文字幕一区二区 | 香蕉网站在线观看影院 | 日本一区二区三区在线观看 | 午夜成人在线视频 | 99尹人香蕉国产免费天天拍 | 色狠狠色综合久久8狠狠色 色狠狠婷婷97 | 婷婷夜夜躁天天躁人人躁 | 99久久精品费精品国产一区二 | 久久综合一区二区三区 | 二区不卡 | 深夜福利国产精品亚洲尤物 | 亚洲欧美日韩在线精品2021 | 欧美一级级a在线观看 | 欧美激情一区二区三区中文字幕 | 欧美一级毛片高清免费观看 | aaa一级毛片 | 成人久久网 | 日韩欧美在线观看视频一区二区 | 亚洲视频第二页 | 看免费一级毛片 | 国产成人在线播放视频 | 黄色网欧美| 日韩国产在线 | 国内在线观看 | 女bbbbxxx| 亚洲国产欧美久久香综合 | 国产或人精品日本亚洲77美色 |