我有href
个元素。之后,我将subString ......制作为新的href
,并希望将其设置回element。但是Selenium没有setAttribute
方法
nextListByNumber = driver.findElement(By.xpath("//*[@id='paginater']//*[text()='"+2+"']"));
String href = nextListByNumber.getAttribute("href");
int manualcode1 = href.lastIndexOf("MANUAL");
int manualcode2 = href.lastIndexOf("/sort");
String manualcode = href.substring(manualcode1, manualcode2);
String hrefNew = "http://localhost/jp/courseassign/course_assign_search_result/"+manualcode+"/sort:User.login_id/direction:asc/page:"+i+"?limit=20";
答案 0 :(得分:1)
您可以为此使用JavaScript
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].setAttribute(arguments[1], arguments[2]);", nextListByNumber, "href", hrefNew);