Есть отличная удаленная работа для php+codeception+jenkins+allure+docker спецов. 100% remote! Присоединиться к проекту

Click on a generic element from a generic list

robot-framework
python
Теги: #<Tag:0x00007f7b70a92ae8> #<Tag:0x00007f7b70a929a8>

(Alex) #1

Hello,

Need a help with some ideas how to click on a generic element from a generic list in Robot Framework using Python.

For example, I need to select last list element, that is <div class="venue-item">, from the following list:<div id="list">. And click on the following tag <a href="#" class="venue-actions dropdown-toggle" data-toggle="dropdown"></a>

May be to create a Python library?

I updated the code to be more clearly, that wanted tag to click is repeating in all generics parent DIV tags

<div id="list" class="row" style="opacity: 1;">
  <div class="venue-item">
      <a class="venue-actions dropdown-toggle" data toggle="dropdown" href="#"></a>
      <ul class="dropdown-menu">
      <h3>test_by_alex_lggge</h3>
      <a class="show-details-btn" href="#">
  <div class="venue-item">
      <a class="venue-actions dropdown-toggle" data toggle="dropdown" href="#"></a>
      <ul class="dropdown-menu">
      <h3>test_by_alex_lggge</h3>
      <a class="show-details-btn" href="#">
  <div class="venue-item">
      <a class="venue-actions dropdown-toggle" data toggle="dropdown" href="#"></a>
      <ul class="dropdown-menu">
      <h3>test_by_alex_lggge</h3>
      <a class="show-details-btn" href="#">
  <div class="venue-item">
      <a class="venue-actions dropdown-toggle" data toggle="dropdown" href="#"></a>
      <ul class="dropdown-menu">
      <h3>test_by_alex_lggge</h3>
      <a class="show-details-btn" href="#">
  <div class="venue-item">
      <a class="venue-actions dropdown-toggle" data toggle="dropdown" href="#"></a>
      <ul class="dropdown-menu">
      <h3>test_by_alex_lggge</h3>
      <a class="show-details-btn" href="#">
  <div class="venue-item">
      <a class="venue-actions dropdown-toggle" data toggle="dropdown" href="#"></a>
      <ul class="dropdown-menu">
      <h3>test_by_alex_lggge</h3>
      <a class="show-details-btn" href="#">
  <div class="venue-item">
      <a class="venue-actions dropdown-toggle" data toggle="dropdown" href="#"></a>
      <ul class="dropdown-menu">
      <h3>test_by_alex_lggge</h3>
      <a class="show-details-btn" href="#">
  <div class="item-detail">
      <a class="venue-actions dropdown-toggle" data toggle="dropdown" href="#"></a>
      <ul class="dropdown-menu">
      <h3>test_by_alex_lggge</h3>
      <a class="show-details-btn" href="#">
 </div>
 <div class="organisation-details">
 <div id="delete-schedule-26681" class="modal fade" role="dialog">
 </div>
</div>


(Ярослав Бойко) #2

try next xpath:
1.

"//div[@id='list']/div[@class='item-detail']/a[@class='venue-actions dropdown-toggle']"

OR
2.

"//a[@class='venue-actions dropdown-toggle']"

OR
3.

"//div[@id='list']"       click
wait to be visible   "//div[@class='item-detail']"
"//div[@class='item-detail']"     click
wait to be visible   "//a[@class='venue-actions dropdown-toggle']"
"//a[@class='venue-actions dropdown-toggle']"     click

(Alex) #3

Thanks, looks good.
But I did a mistake and didn’t mention that wanted tag is repeating in all parent div tags.
I updated description.


(Ярослав Бойко) #4

try next xpath:
1.

"//div[@id='list']"       click
wait to be visible   "//div[@class='item-detail']"
"//div[@class='item-detail']"     click
wait to be visible   "(//a[@class='venue-actions dropdown-toggle'])[last()]"
"(//a[@class='venue-actions dropdown-toggle'])[last()]"     click

OR
2.

"//div[@id='list']"       click
wait to be visible   "//div[@class='item-detail']"
"//div[@class='item-detail']"     click
wait to be visible   "(//a[@class='venue-actions dropdown-toggle'])[8]"
"(//a[@class='venue-actions dropdown-toggle'])[8]"     click

(Alex) #5

OK, thanks a lot, Yaroslav.
I will be back ASAP with a response in case I succeeded.


(Taras) #6

better to use contains while searching elements with split classes,[contains(@class,‘venue-actions’) and contains(@class,‘dropdown-toggle’)] instead of @class=‘venue-actions dropdown-toggle’


(Alex) #7

Hi Yaroslav,

Checked finally.
I used your idea with “[last()]” and it works.

My xpath looks following: //div[@id="list"]/div[@class="venue-item"][last()]/a[@data-toggle="dropdown"]