简体   繁体   English

FindElements By.Xpath 在 linux 中不起作用

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

I have 5 elements and I want to get 1the first element and click it.我有 5 个元素,我想获取第一个元素并单击它。 When I try my code on windows I can get all elements and it is working and I can click that element and download excel1.当我在 windows 上尝试我的代码时,我可以获得所有元素并且它正在工作,我可以单击该元素并下载 excel1。 But when I push my code to linux it does not work in my link returns null.但是,当我将代码推送到 linux 时,它在我的link中不起作用,返回 null。 How can I click it.我怎么能点击它。

My code:我的代码:

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(); 

and my elements和我的元素

<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>

You are probably missing a delay before accessing these elements.在访问这些元素之前,您可能错过了延迟。
To check this issue just put some delay of several seconds before要检查此问题,只需延迟几秒钟即可

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

line.线。 In case it fixed the problem use WebDriverWait expected conditions explicit waits instead the hardcoded pause to make your code better.如果它解决了问题,请使用WebDriverWait预期条件显式等待而不是硬编码暂停以使您的代码更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM