0

My code is below, I am having problems with 'Production Plan', I need to be able to click the Production Plan link but it doesn't work.

 List<WebElement> ddOpts = driver.findElements(By.xpath("html/body/div[4]"));
 ArrayList<String> links = new ArrayList<String>();
 for(WebElement we : ddOpts) {
 //System.out.println(we.getText());
 links.add(we.getText());
 System.out.println(links);
 if(we.getText().contains("Production Plan")) {
 we.sendKeys("Production Plan");
 we.click();
 }
C_B
2,6803 gold badges25 silver badges47 bronze badges
asked Mar 6, 2014 at 9:47

2 Answers 2

0

Your WebElements in ddOpts list aren't an anchor tags but divs. I don't know how does the page look, but it seems you might thought another xpath. Something like:

List<WebElement> ddOpts = driver.findElements(By.xpath("html/body/div/a[4]"));

or

List<WebElement> ddOpts = driver.findElements(By.xpath("html/body/div[4]/a"));

Or maybe if it is a select option, use a Select object

Select mySelect = new Select(driver.findElements(By.xpath("html/body/div[4]")));
mySelect.selectByVisibleText("Production Plan");

see answer of this question: How to select an option from a drop-down using Selenium WebDriver with Java?

answered Mar 6, 2014 at 9:55
Sign up to request clarification or add additional context in comments.

Comments

0

I didn't understand why your trying to sendKeys().

But If you are trying to click on a link, following will work :

WebElement link = driver.findElement(By.PartialLinkText("Production Plan"));
link.click();

or

You can also try with Explicit wait :

new WebDriverWait(driver, 30).until(ExpectedConditions.visibilityOfElementLocated(By.PartialLinkText("Production Plan"))).click();
answered Mar 6, 2014 at 10:13

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.