Repository navigation
Expand file tree
/
Copy pathGetValue
More file actions
86 lines (73 loc) · 2.76 KB
/
Copy pathGetValue
File metadata and controls
86 lines (73 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import com.testsigma.customfunc.common.CustomTestStep;
import com.testsigma.customfunc.common.TestsigmaCustomFunctions;
import com.testsigma.customfunc.result.ResultConstants;
import com.testsigma.customfunc.result.TestStepResult;
public class GetValue extends TestsigmaCustomFunctions {
TestStepResult result=new TestStepResult();
StringBuffer sb=new StringBuffer();
@CustomTestStep
public TestStepResult getValofElement(String LocatorType,String LocatorValue) throws Exception {
try {
if(LocatorType.equalsIgnoreCase("Xpath")) {
try {
WebElement a1=driver.findElement(By.xpath(""+LocatorValue+""));
String val=a1.getAttribute("value");
result.setStatus(ResultConstants.SUCCESS);
result.setMessage("The value of the attribute is "+val);
}
catch(NoSuchElementException ne) {
result.setStatus(ResultConstants.FAILURE);
result.setMessage("No Element Found with the Xpath"+LocatorValue);
}
catch(Exception e) {
result.setStatus(ResultConstants.FAILURE);
result.setMessage("Thrown Exception is "+ sb.append(e.getMessage()).toString());
}
}
else if(LocatorType.equalsIgnoreCase("id")) {
try {
WebElement a1=driver.findElement(By.id(""+LocatorValue+""));
String val=a1.getAttribute("value");
result.setStatus(ResultConstants.SUCCESS);
result.setMessage("The value of the attribute is "+val);
}
catch(NoSuchElementException ne) {
result.setStatus(ResultConstants.FAILURE);
result.setMessage("No Element Found with the id"+LocatorValue);
}
catch(Exception e) {
result.setStatus(ResultConstants.FAILURE);
result.setMessage("Thrown Exception is "+ sb.append(e.getMessage()).toString());
}
}
else if(LocatorType.equalsIgnoreCase("CssSelector")) {
try {
WebElement a1=driver.findElement(By.cssSelector(""+LocatorValue+""));
String val=a1.getAttribute("value");
result.setStatus(ResultConstants.SUCCESS);
result.setMessage("The value of the attribute is "+val);
}
catch(NoSuchElementException ne){
result.setStatus(ResultConstants.FAILURE);
result.setMessage("No Element Found with the CssSelector"+LocatorValue);
}
catch(Exception e) {
result.setStatus(ResultConstants.FAILURE);
result.setMessage("Thrown Exception is "+ sb.append(e.getMessage()).toString());
}
}
else {
result.setStatus(ResultConstants.FAILURE);
result.setMessage("Operation Failure You may consider using id/Xpath/CssSelector");
}
}
catch(Exception e) {
result.setStatus(ResultConstants.FAILURE);
result.setMessage("Thrown Exception is "+ sb.append(e.getMessage()).toString());
}
return result;
}
}