Andrew,
On 11/June/2018 you raised following question in the post:
The scenario is very simple. Click on the email arrived.
Created my own test object and called it Email1.
Xpath: id(“:38”)/span[@class=“bA4”]/span[@class=“yP”]
I get this error:
Unable to click on object ‘Object Repository/Page_Inbox (479) - andrewkhomskigma/Email1’ (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/Page_Inbox (479) - andrewkhomskigma/Email1’ located by ‘By.xpath: id(“:38”)/span[@class=“bA4”]/span[@class=“yP”]’ not found)
What you called ‘email’ here is the Google Mail.
## What I did
I made a Katalon Studio project for my experiment. This project logs into GMail with my personal credential. The test case checks the gmail page where a list of incoming mails are displayed. The test case selects the row of 1st incoming mail, then click the sender name to jump to the content page. The test case works.
My test case is as follows:
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testobject.ConditionType as ConditionType
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
// login into GMail with my account
WebUI.callTestCase(findTestCase('Login'), ['userid':'','password':''], FailureHandling.STOP_ON_FAILURE)
// create a Test Object on the fly. We do not use the Object Repository here.
def testobject = new TestObject("1st mail sender")
// The Gmail, list of inbox, 1st row, sender name
def expr = '//table/tbody/tr[1]/td[5]/div[2]/span/span'
testobject.addProperty("xpath", ConditionType.EQUALS, expr)
WebUI.verifyElementPresent(testobject, 10, FailureHandling.STOP_ON_FAILURE)
def content = WebUI.getText(testobject, FailureHandling.OPTIONAL)
WebUI.comment("content=${content}")
// now click the sender name to see the indivisual mail content
WebUI.click(testobject)
Thread.sleep(5000)
WebUI.closeBrowser()
## What I found
Andrew, you could not click the 1st email. But I could do it. What is the difference? — we use different XPath expressions.
Andrew used the following XPath expression:
id(":38")/span[@class="bA4"]/span[@class="yP"]
I used the following expression:
//table/tbody/tr[1]/td[5]/div[2]/span/span
I observed HTML DOM of the Google Mail page carefully. For example, the table tag as the list of email was once marked up as follows:
<table id=":2p"> ....</table>
I thought that the values of id
attributes (:2p
in the above example) is dynamically allocated by the server-side application. I thought the markup MAY (likely to) change as follows:
<table id=":2q"> ....</table>
I thought that the id value in Gmail page is unstable so that my XPath should not rely on the id values.
## Answer to the original question
I think, Andrew’s XPath expression id(":38")
was once valid but it turned invalid sometime after the id value is reassigned by the Gmail server app.