-1

I'm trying to find attribute using find_element_by_xpath with multiple attributes.

HTML:

<table id="idMainGridhistoryHeader" border="0" class="adodb_dbgrid" qhelp="2.2_zahlavisloupce">
...
</table>

<table id="idMainGridhistory" agname="history" userid="1" entityidcolumnname="hi_id" editable="1" border="0" class="adodb_dbgrid" scrollx="0">
... # id I want to find idMainGridhistory
</table>

I was tried this:

driver.find_element_by_xpath("//table[contains(@class, 'adodb_dbgrid') and contains(@userid, '1')]").get_attribute('id')

And this:

driver.find_element_by_xpath("//table[@class='adodb_dbgrid'][@userid='1']").get_attribute('id')

but everything will return Unable to locate element. Any advice how to find it with multiple elements?

Community
  • 1
  • 1
Pivoman
  • 4,435
  • 5
  • 18
  • 30
  • `"//table[@class='adodb_dbgrid'][@userid='1']"` this `xpath` means that your element has both attributes, but those attributes belongs to different elements... Clarify what exactly you want to do – Andersson Feb 15 '16 at 11:46
  • that element table has attributes id="idMainGridhistory" agname="history" userid="1" entityidcolumnname="hi_id" editable="1" border="0" class="adodb_dbgrid" scrollx="0" (In that second table. First table is just reason why I can't find it by one parameter). – Pivoman Feb 15 '16 at 12:22
  • My fail was in bad choose of parameter userid='1'. userid is parameter, that is variable. With other parameter for ex. editable='1' it works – Pivoman Feb 15 '16 at 13:39

2 Answers2

1

There are a lot of other ways how to find second table. Choose one you more like: 1. From list of tables by index

driver.find_elements_by_tag_name('table')[1].get_attribute('id')

2. By original attribute

driver.find_elements_by_xpath('//table[@userid="1"]').get_attribute('id')

3. More specific

driver.find_elements_by_xpath('//table[@agname="history"][@class="adodb_dbgrid"]').get_attribute('id')
Andersson
  • 51,635
  • 17
  • 77
  • 129
0

Try this one:

driver.find_element_by_xpath("//table[@class='adodb_dbgrid'and @userid='1']").get_attribute('id')
Floern
  • 33,559
  • 24
  • 104
  • 119
Rajni
  • 11
  • My fail was in bad choose of parameter userid='1'. userid is parameter, that is variable. With other parameter for ex. editable='1' it works. But thx. – Pivoman Feb 15 '16 at 13:41