0

I've tried several xpath's for choosing the dropdown list. But nothing is worked.

Some of the xpath's I used are as follows:

By.xpath("//table/tbody/tr[2]/td[2]/span").click;

Or

By.xpath("/td[2]/span[contains(text(),'NATIONAL IDENTITY DOCUMENT')]").click;

Please find the below html tags, I need to select the value either 'ASYLUM SEEKER PERMIT DOCUMENT' or 'NATIONAL IDENTITY DOCUMENT'.

<tbody>
<tr id="jP2Qrg" class="z-comboitem">
<td class="z-comboitem-img"/>
<td class="z-comboitem-text">
<span class="z-comboitem-spacer"/>
ASYLUM SEEKER PERMIT DOCUMENT
</td>
</tr>
<tr id="jP2Qsg" class="z-comboitem z-comboitem-over">
<td class="z-comboitem-img"/>
<td class="z-comboitem-text">
<span class="z-comboitem-spacer"/>
NATIONAL IDENTITY DOCUMENT
</td>
</tr>
</tbody>

When I try to take xpath using firepath, it is dynamic. Every time the xpath and the id is keep changing. So please suggest the xpath which works.

SAUMARS
  • 73
  • 1
  • 11

6 Answers6

2

The text is not inside the span text and it is in second td tag. you can try with small change in your code as given below.

By.xpath("//table/tbody/tr[2]/td[2]").click;

or

By.xpath("//td[contains(text(),'NATIONAL IDENTITY DOCUMENT')]").click;
Andersson
  • 51,635
  • 17
  • 77
  • 129
Murthi
  • 5,299
  • 1
  • 10
  • 15
  • Thanks for your reply. I tried this as well. But it didn't work. – SAUMARS Jul 31 '17 at 13:16
  • But, In firepath when I use the below 1. It is getting highlighted. But not working inn the script. By.xpath("//table/tbody/tr[2]/td[2][@class = 'z-comboitem-text']").click; – SAUMARS Jul 31 '17 at 13:24
  • you can try clicking on image instead of text. By.xpath("//table/tbody/tr[2]/td[@class = 'z-comboitem-img']").click; – Murthi Jul 31 '17 at 13:45
  • No luck, It is clicking on drop-down and not getting the value selected. Getting exception error. – SAUMARS Jul 31 '17 at 13:52
0

Can you check this..,

By.xpath("//*[contains(text(),'NATIONAL IDENTITY DOCUMENT')]").click;

By.xpath("//*[contains(text(),'ASYLUM SEEKER PERMIT DOCUMENT')]").click;
santhosh kumar
  • 1,981
  • 1
  • 9
  • 28
0

Try to use below XPath to match required option:

By.xpath("//td[normalize-space()='ASYLUM SEEKER PERMIT DOCUMENT']").click;

or

By.xpath("//td[.='ASYLUM SEEKER PERMIT DOCUMENT']").click;

As @Murthi said, text node is not a child of span, but td. Note that there are some specifics in locating text nodes

Andersson
  • 51,635
  • 17
  • 77
  • 129
  • Can you share exception log? – Andersson Jul 31 '17 at 13:24
  • This is the exception I got. <<< Unable to Click button OBJ_IDType_DROPDOWN >>> Timed out after 20 seconds waiting for element to be clickable: [[InternetExplorerDriver: internet explorer on WINDOWS (b924b52b-0aee-4092-a430-2759ac4ec637)] -> xpath: //table/tbody/tr[2]/td[2][@class = 'z-comboitem-text']] Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52' System info: host: '0967JNBPBB010L', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_76-ea' Driver info: org.openqa.selenium.ie.InternetExplorerDriver – SAUMARS Jul 31 '17 at 13:30
  • It's not my Xpath in provided stacktrace. Do not use `tbody` tag in your XPath. Can you share exact output when applying my solution? – Andersson Jul 31 '17 at 13:35
  • Yes, the Xpath which is provided in stacktrace is not given by you. But this is the only xpath getting highlighted in application using firpath. //tr[2]/td[2][@class = 'z-comboitem-text'] – SAUMARS Jul 31 '17 at 13:42
  • Did you try it in Firepath only? Try in Selenium code – Andersson Jul 31 '17 at 13:47
  • Nope, I tried in both firepath as well as selenium code. I'm getting same exception error. <<< Unable to Click button OBJ_IDType_DROPDOWN >>> Timed out after 20 seconds waiting for element to be clickable: [[InternetExplorerDriver: internet explorer on WINDOWS (f9fd0055-0f34-4830-84ed-aef18e263181)] -> xpath: //td[normalize-space()='ASYLUM SEEKER PERMIT DOCUMENT']] Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52' – SAUMARS Jul 31 '17 at 13:55
  • Did you click on appropriate element to populate drop-down menu? Can you update the ticket with some more code? – Andersson Jul 31 '17 at 14:51
0

Here is the Answer to your Question:

To click on ASYLUM SEEKER PERMIT DOCUMENT you can use the following xpath:

By.xpath("//td[contains(.,'ASYLUM SEEKER PERMIT DOCUMENT') and not (@class='z-comboitem-spacer')]").click;

Let me know if this Answers your Question.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

How about this xpaths,

Updated code

(//td[2])[1]//*[starts-with(@class,"z-com")]; // Selects ASYLUM..
(//td[2])[2]//*[starts-with(@class,"z-com")]; // Selects NATIONAL..

This should work if it doesn't have same class name in the same position.

Old xpath's

driver.findelement(By.xpath("(//td[2])[1]")); // selects ASYLUM SEEKER PERMIT DOCUMENT 

driver.findelement(By.xpath("(//td[2])[2]")); // selects NATIONAL IDENTITY DOCUMENT 
Chandra Shekhar
  • 664
  • 2
  • 9
  • 24
  • Thanks for your reply. Since there are lot of td[2] in that application. Even I tried with this now, It didn't work. – SAUMARS Aug 01 '17 at 13:27
0

Find out the solution for selecting the dropdown options.

By using List method, I took the list of options available in that field and selected by using clicking the index value of list.

 List<WebElement> Idtype = driver.findElements(By.xpath("//tr[2]/td[2][@class = 'z-comboitem-text']"));
    Idtype.get(0).click();
SAUMARS
  • 73
  • 1
  • 11