i am trying to get a value from List and then change the value if its not what i expect. what i am trying to do is navigate to next page. the website has "previous", "1" and so on. i want to get "previous" from the list and then change it to "2" so that i will be able to navigate forward. please let me know if i am able to explain well.Please see my below code, is there any way i could change the list value? what i am doing is not working:
try {
nextPage_02 = driver.findElements(By.xpath("//a[contains(@href,'=sr_pg_')]"));
if (nextPage_02 != null || ((WebElement) nextPage_02).isDisplayed()) {
for(WebElement g : nextPage_02) {
if(g.getText().equals("previous")) {
g.getText().replace("previous", "0") ;
System.out.println(g.getText());
int nextPageToInt = Integer.parseInt(g.getText());
int nextPage_content ;
int i ;
for(i= 0 ; i < 4 ; i++) {
nextPage_content = nextPageToInt + i;
if(nextPageToInt == nextPage_content ) {
((WebElement) nextPage_02).click();
}
}
}
If you want to change the value that you get from list instead of changing the list value on webpage, you can do like this:
try {
public static List<WebElement> nextPage_02 = driver.findElements(By.xpath("//a[contains(@href,'=sr_pg_')]"));
for (WebElement g : nextPage_02) {
String str = g.getText();
if(str.equals("someText")) {
str = str.replaceAll("someText", "2") ;
int nextPageToInt = Integer.parseInt(str);
// do something with nextPageToInt??
}
}
}
If you want to change the list value on webpage, please let us know more about your true intentions.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.