0

I am having trouble clicking on a link in a webpage using the selenium webdriver in firefox.

Here is a snippet of my code regarding the issue:

WebElement option = driver.findElement(By.id("AccNumSpan" + i));
                if(option.getText().contains("48494")){ 
                    List <WebElement> listOfOptions1 = driver.findElements(By.xpath("//*[@id='row" + i +"']/td[10]/nobr"));
                    for(WebElement option1 : listOfOptions1){
                        System.out.println(option1.getText());

                        String id = option1.getAttribute("id");
                        System.out.println(id);
                        option1.click();
}

Here is the html of the link that I am trying to click:

<td class="cell" align="left">
<nobr>
<span id="link15796367" class="stmtListTableLinkDocument" onclick="billDocsClient.ShowDocTypeList(event, 'table#StatementTable', 'span#link15796367', 908244, 15796367, '6728_22198', '48494 (Merrill Lynch Europe PLC)', '6/1/2014', '34969691/175474');" onmouseout="this.className='stmtListTableLinkDocument'" onmouseover="this.className='docLink'">View Monthly Invoices</span>
</nobr>
</td>

When I run the code, it prints "View Monthly Statement" from option1.getText ( so it does find the element), but when I try option1.click() (which is what I want to do) nothing happens except the text gets underlined or whatever but the link isn't opened. Also, it does not print anything for option1.getAttribute("id") or for any attribute using .getAttribute

Any way to get around this? All help is appreciated, thanks

2
  • 1
    I'm confused. Do you mean getText() is printing View Monthly Invoices? Also, can you show more of the html so we can see the element with id AccNumSpan? Commented Jun 17, 2014 at 22:03
  • SiKing provided a fix, thanks though Commented Jun 17, 2014 at 22:06

2 Answers 2

2

Try clicking on the span element below your nobr:

option1.findElement(By.xpath("span")).click();

as that seems to be the clickable element.

Sign up to request clarification or add additional context in comments.

1 Comment

This worked, thank you. I shall name my first born child after you SiKing
0

You can also try this :

driver.findElement(By.linkText("View Monthly Invoices")).click()

3 Comments

While this code may help answer the qusetion, code only answers are not high quality. A better answer would explain what the code does, tell where to insert it, explain why this approach was taken, and link to relevant documentation.
insert it at place of option1.click(); It will find link with text "View Monthly Invoices" and then perform click operation.
That's basically what I was doing. It didnt actually click the link just clicked the text. SiKing provided the fix; thanks for your input though

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.