How to use getAttribute in 10.3.1

Upgraded from 9.7.5 to 10.3.1 and now all instances of the call .getAttribute() no longer function. How am I supposed to use it?

Example: 

for (Thumb in ThumbsPresent) {
				def ThumbLink = Thumb.findElement(By.xpath(".//div[contains(@class, 'imageColumn')]//a")).getAttribute("href")
				def ThumbLinkText = Thumb.findElement(By.xpath(".//div[contains(@class, 'margin')]//a")).getText().trim()
				ThumbLinks[ThumbLinkText]= ThumbLink
				def ThumbSrc = Thumb.findElement(By.xpath(".//img")).getAttribute("src")
				println("ThumbLink: ${ThumbLink}")
				println("ThumbSrc: ${ThumbSrc}")
			}
Example2: 
WebElement BatchProcessing = driver.findElement(By.xpath(xpath))

String id = BatchProcessing.getAttribute("id")
1 Like

Really? I didn’t know that.

I just googled for some references, and found the following:

1 Like

I know Katalon Studio v10.2 and newer uses Selenium v4.28.1. I checked the source code of Katalon Studio v10.3.1 and found the WebUI.getAttribute(TestObject,String) keyword is not using driver.getDomAttribute and driver.getDomProperty methods at all. I got a question: does the WebUI.getAttribute() keyword work in Katlaon Studio v10.3.1?


In the javadoc of Selenium v4.28.1,


I wrote the following Test Case script, and ran it using Katalon Studio v10.3.1. The editor stroke out the call to getAttribute. But when I ran the script, I ran fine. So I understand that the getAttribute method is depreceted but not yet removed; so it is still usable in the Selenium v4.28.1 in the Katalon studio v10.3.1.

import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase

import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.webui.driver.DriverFactory
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.By

import internal.GlobalVariable as GlobalVariable

TestObject makeTestObject(String id, String xpath) {
	TestObject tObj = new TestObject(id)
	tObj.addProperty("xpath", ConditionType.EQUALS, xpath)
	return tObj	
}

WebUI.openBrowser(GlobalVariable.G_SiteURL)
WebUI.callTestCase(findTestCase('Common Test Cases/Login'), 
		[('Username') : 'John Doe', ('Password') : 'ThisIsNotAPassword'],
		FailureHandling.STOP_ON_FAILURE)

TestObject hospitalReadmission = 
	makeTestObject("check_hospital_readmission", 
					"//input[@name='hospital_readmission']")
WebUI.verifyElementPresent(hospitalReadmission, 10)

/*
String value = WebUI.getAttribute(hospitalReadmission, "value")
assert value == "Yes"
 */

WebDriver driver = DriverFactory.getWebDriver()
WebElement webElement = driver.findElement(By.xpath("//input[@name='hospital_readmission']"))
String v = webElement.getAttribute("value")   // Stroke out!
assert v == "Yes"

WebUI.closeBrowser()


“no longer function” — I do not see what @josh.meeks meant.

I think, WebElement.getAttribute() still works in Katalon Studio v10.3.1

You should use JavaScript execution to retrieve the DOM property instead. Here’s how to rewrite your code

WebDriver driver = DriverFactory.getWebDriver()

WebElement BatchProcessing = driver.findElement(By.xpath(xpath))

String id = WebUI.executeJavaScript(“return arguments[0].id;”, Arrays.asList(batchProcessing))

println("ID: " + id)

2 Likes

1 Like