0

My problem mainly is that my code doesn't run, I tried for more than 2 hours. I have seen many posts also, but some are written in different computer languages (not in Java), so I am confused now.

Below is my code for just clicking a button. All I want to do is click a button and go to new page.

 WebDriver driver = new HtmlUnitDriver();
 driver.get("file:///C:/Users/Sanya/Desktop/New%20folder%20(2)/page%203%20alerts.htm");

 WebElement element = driver.findElement(By.partialLinkText("Alert"));
 element.click();
4
  • What is the source code of the button that you are trying to click on? Commented Feb 15, 2014 at 5:50
  • can we see the html part? Commented Feb 15, 2014 at 7:02
  • <li title="Alerts"><a href="/botnets/botnets" onclick="setTimeout(showLoading, 50);"><span>Alerts</span></a></li> Commented Feb 15, 2014 at 15:53
  • That is how the "Alerts" look like. Commented Feb 15, 2014 at 15:54

3 Answers 3

1

Try this it works fine for me:

WebElement menuHoverLink = driver.findElement(By.id("your_id"));
actions.moveToElement(menuHoverLink).perform();
Sign up to request clarification or add additional context in comments.

Comments

0

You can try the below one...

Actions action = new Actions(driver);
action.click(driver.findElement(By.partialLinkText("Alert"))).build().perform();

It was worked for me :-)

4 Comments

Hey! I have been getting "Obsolute method on stack" error. Would you have any idea what could be wrong?
I had used the same code you provided me. Ill update my question
I gave the information in the question, if you got ANY idea please help me out, I have tried over 6 hours now.
Try with xpath //li[@title='Alerts']/a/span
0

You can use XPath for instance to locate the element on your page:

By locator = By.xpath("//li[@title='Alerts']/a");
WebElement element = driver.findElement(locator);

Here is more information about how XPath works.

Comments

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.