簡體   English   中英

FindElements By.Xpath 在 linux 中不起作用

[英]FindElements By.Xpath is not working in linux

我有 5 個元素,我想獲取第一個元素並單擊它。 當我在 windows 上嘗試我的代碼時,我可以獲得所有元素並且它正在工作,我可以單擊該元素並下載 excel1。 但是,當我將代碼推送到 linux 時,它在我的link中不起作用,返回 null。 我怎么能點擊它。

我的代碼:

var link = driver.FindElements(By.XPath("//div[@class='mt-3 mb-3 w-100 border-bottom']")); //i can not get my elements on linux
link[1].Click(); 

和我的元素

<div>
  <div class="mt-3 mb-3 w-100 border-bottom" style="padding-left: 1%; padding-right: 1%;"><a class="text-secondary" style="font-size: 1.2rem; color: #0c0c0c; cursor: pointer;"><span style="font-weight: bold;">Table-1</span> click download for excel0</a></div>
  <div class="mt-3 mb-3 w-100 border-bottom" style="padding-left: 1%; padding-right: 1%;"><a class="text-secondary" style="font-size: 1.2rem; color: #0c0c0c; cursor: pointer;"><span style="font-weight: bold;">Table-2</span> click download for excel1</a></div>
  <div class="mt-3 mb-3 w-100 border-bottom" style="padding-left: 1%; padding-right: 1%;"><a class="text-secondary" style="font-size: 1.2rem; color: #0c0c0c; cursor: pointer;"><span style="font-weight: bold;">Table-3</span> click download for excel2</a></div>
  <div class="mt-3 mb-3 w-100 border-bottom" style="padding-left: 1%; padding-right: 1%;"><a class="text-secondary" style="font-size: 1.2rem; color: #0c0c0c; cursor: pointer;"><span style="font-weight: bold;">Table-4</span> click download for excel3</a></div>
  <div class="mt-3 mb-3 w-100 border-bottom" style="padding-left: 1%; padding-right: 1%;"><a class="text-secondary" style="font-size: 1.2rem; color: #0c0c0c; cursor: pointer;"><span style="font-weight: bold;">Table-5</span> click download for excel4</a></div>
</div>

在訪問這些元素之前,您可能錯過了延遲。
要檢查此問題,只需延遲幾秒鍾即可

var link = driver.FindElements(By.XPath("//div[@class='mt-3 mb-3 w-100 border-bottom']")); //i can not get my elements on linux

線。 如果它解決了問題,請使用WebDriverWait預期條件顯式等待而不是硬編碼暫停以使您的代碼更好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM