1
public void click()
{                               
    List<WebElement> list = driver.findElement(By.xpath("//a[contains(text(),'javascript:toggleEnabled']@href + /a//img[@title='Inactive']"));  
    list.click          
}

I am not able to click on title = "Inactive" in javascript console. The HTML code is mentioned below.

<a href="javascript:toggleEnabled('Collaboration: Browse -> Buy');">
 <img src="/console/themes/images/new_imgs/status_light_off.png" style="width:24px; height:24px;" alt="Inactive" title="Inactive">
</a>

ConsoleExample

Conslole Example are 2

Console example 3

2 Answers 2

1

As per the HTML to click on the element you can use the following line of code : :

driver.findElement(By.xpath("//a/img[contains(@src,'/console/themes/images/new_imgs/status_light_off.png')]")).click();
Sign up to request clarification or add additional context in comments.

Comments

0

After getting some more info, using title='Inactive' was not enough to be unique. Adding a check on the href should take care of it. Switching to CSS selector since XPath is not required for this locator.

By.cssSelector("a[href*='Buy'][title='Inactive']")

7 Comments

It is clicking on another console light exactly next to it mentioned here <a href="javascript:forceRun('Best sellers');"> <img src="/console/themes/images/new_imgs/status_light_off.png" style="width:24px; height:24px;" alt="Inactive" title="Inactive"> </a>
It should click on the following html / javascript console... <a href="javascript:toggleEnabled('Collaboration: Browse -> Buy');"> <img src="/console/themes/images/new_imgs/status_light_off.png" style="width:24px; height:24px;" alt="Inactive" title="Inactive"> </a>
Tried this ::::driver.findElement(By.xpath("//a[contains(text(),'javascript:toggleEnabled']@href + /a//img[@title='Inactive']")); but cannot enable to recognise the xpath
Updated my answer based on the additional HTML.
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"a[href*='Buy'][title='Inactive']"} -- Thanks but still error continues.
|

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.