Not able to select element by xpath - JAR file has no source attachement

Hi,

I’m trying to select an element by using xpath.

WebElement aaa = driver.findElement(By.xpath(“//*[@ id =‘my-id’]”))
WebElement ttt = driver.findElement(By.xpath(“//*[contains(@ data-city,‘ATL’)]”))

However it’s giving me error just like below image.

Debug mode:

So, I attached Source like below.

Then I get this error

Please let me know what I’m missing.

Thanks,
Jiho

Capture2.PNG

Capture3.PNG

Are you using Debug mode for test case? Please stop using debug mode — it would confuse you rather than helping you.

Just run the test case and see out-coming messages in the Console view. Do you find any error message?

I got those two console msgs. Could you check them please?

console2.PNG

console1.PNG

In the log, you can find a message:

Reason:org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element:{"method":"xpath", "selector":"//*[contains(@data-terminal,'ALE')]"}

This is clearly telling you the reason why you got error.

Jiho,

Are you sure the XPath is expressing what you intended?
You should make sure how the HTML is coded. Please share the HTML code.

In the original post, you showed the following test case snippet:

WebElement aaa = driver.findElement(By.xpath("//*[@ id ='my-id']"))
WebElement ttt = driver.findElement(By.xpath("//*[contains(@ data-city,'ATL')]"))

These 2 lines does not include the XPath "//*[contains(@data-terminal,'ALE')]" which is in question. You are looking at different portion. Please review your code and find which portion is to be investigated. Is the portion enclosed in

It is likely that you need to do some waiting for the element.