简体   繁体   中英

FindElements By.Xpath is not working in linux

I have 5 elements and I want to get 1the first element and click it. 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. But when I push my code to linux it does not work in my link returns 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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