2017-10-19 77 views
1

我想點擊按鈕上傳完成的表單,通過硒使用XPath,但是這不會做任何事情與它的XPath,我想知道如果有人有任何建議的答案?在C#中使用Selenium上傳文件?

enter image description here

下面是檢查Chrome瀏覽器的HTML。

<button ng-if="$root.AccessLevel.Standard" class="btn btn--small btn--icon ng-pristine ng-valid ng-touched" ng-model="vm.uploads[workCategory.Id].reference" ngf-max-size="'5MB'" ngf-model-invalid="vm.uploads[workCategory.Id].referenceInvalid" ngf-pattern="'.pdf,.doc,.docx,.bmp,.gif,.jpg,.jpeg,.tif,.wmf,.png'" ngf-select="vm.uploadFile($file, 'WorkCategoryReference', workCategory.Id, workCategory.References, workCategory.Id+'uploadRef')"> 
    <span promise="vm.promises[workCategory.Id+'uploadRef']"> 
     <span ng-hide="pending" class=""> 
      <i class="fa fa-lg fa-cloud-upload"></i> 
     </span> 
     <span ng-show="pending" class="ng-hide"> 
      <i class="fa fa-lg fa-refresh fa-spin"></i> 
     </span> 
    </span> 
    Upload completed form 
</button> 

下面是我用的XPath的NUnit類

wait.PathWaitAndClick(driver, "*[@id=\"accordiongroup - 299 - 4516 - panel\"]/div/div[2]/div[1]/table/tfoot/tr/td/button", 2000); 

通過以下還我使用WebExtension方法。

public static void PathWaitAndClick(this WebDriverWait wait, IWebDriver driver, string path, int pause = 0) 
{ 
    if (pause > 0) 
    { 
     System.Threading.Thread.Sleep(pause); 
    } 
    wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath(path))); 
    IWebElement viewAllWc = driver.FindElement(By.XPath(path)); 
    if (pause > 0) 
    { 
     System.Threading.Thread.Sleep(pause); 
    } 
    viewAllWc.Click(); 
} 
+0

三個簡單的問題:您的xpath是否在點擊時刻有效? iframe標籤中的按鈕是?你可以暫停你正在運行的方法,並檢查是否有一些錯誤在瀏覽器控制檯丟失? –

+0

它沒有,打我的折點@StriterAlfa –

+0

你可以檢查你的xpath是否有效使用命令$ x(「你的xpath」)在鉻控制檯。你也可以檢查它是否在iframe中檢查頁面的html。如果調試程序無法到達斷點來調試您的單擊操作,則出現錯誤,這不是您要求的幫助 –

回答

1

鑑於您提供HTML的有限範圍內,我將利用contains在你的XPath搜索包含字符串"Upload completed form"給出button元素。

//button[contains(., 'Upload completed form')] 
相關問題