I have this html code
<div pagesequence="46" pagename="page0003">
how can i drive the value of pagename with the help of pagesequence?
i have tried:
driver.findElement(By.cssSelector("div[pagesequence='46']"). );
What do I use to get the value of the pagename attributed, i.e: page0003.
Try the following code
WebElement element = driver.findElement(By.xpath("//div[#pagesequence='46']"));
String pagename = element.getAttribute("pagename");
System.out.println(pagename);
Let me know if this works for you.
you can try below. This should work
List<WebElements> elements = driver.findElements(By.xpath("//div[#pagesequence='46']"));
elements.get(0).getAttribute("pagename");
Try the
driver.findElement(By.cssSelector("div[pagesequence='46']")).getAttribute("pagename");
Related
I need help with extracting parameter from URL. I have used
String url = driver.getCurrentUrl()
to catch current URL.
After that, I need to extract value from the parameter called oauth_verifier from
http://localhost:4200/consent?oauth_token=something&oauth_verifier=something
so I can use it later in code.
Any help would be great. Thanks in advance!
Try This One , I Am not Sure Its Right Way , But Its Work...
String str = "http://localhost:4200/consent?oauth_token=something&oauth_verifier=something";
String[] arrOfStr = str.split("/");
String temp=arrOfStr[3];
String temp2[]=temp.split("\\?|\\=");
To extract the value associated with oauth_verifier you need to induce WebDriverWait with ExpectedConditions as urlContains() the text oauth_verifier and you can use the following solution:
Code Block:
new WebDriverWait(driver, 20).until(ExpectedConditions.urlContains("oauth_verifier"));
String fullUrl = driver.getCurrentUrl();
String[] UrlParts = fullUrl.split("=");
System.out.println(UrlParts[2]);
Console Output:
something
Assuming its Java ,you should use the substring function of String .
yourstring.substring(indexOf1stCharacter,indexOfLastCharacter)
For your case:
url.substring(url.indexOf("oauth_verifier=") + 15 , url.length());
I have a html page:
<video crossorigin="anonymous" class="" id="video" playsinline="true"
src="https://df.dfs.bnt.com/
DEEAB832j06E9j413FjAA8Dj2zxc535DA2072E3jW01j15579/mp4-
hi/jFNf2IbBoGF28IzyU_WqkA,1535144598/zxxx/
contents/1/8/1a57ae021173751b468cca136e0192.mp4?
rnd=0.38664488150364296">
</video>
Through Selenium WebDriver I tried get video url:
By videoLocator = By.id("video");
WebElement videoElement = driver.findElement(videoLocator);
String videoUrl = videoElement.getAttribute("src");
But videoUrl - always returns ""(is empty).
Š¯owever for example:
videoElement.getAttribute("crossorigin")
return correct answer: "anonymous".
I have tried get this url from src attribute using javascript:
String videoUrl = (String) js.executeScript("return document.getElementById( 'video' ).getAttribute( 'src' );");
But the result is still the same: "".
I guess that the problem is in crossorigin="anonymous" but what to do with it? How can I get src value?
Sorry, for my poor English.
As per the HTML you have provided you need to induce WebDriverWait and you can use the following solution:
WebElement videoElement = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//video[#id='video' and #crossorigin='anonymous'][starts-with(#src,'http')]")));
System.out.println(videoElement.getAttribute("src"));
Try fetching innerHTML attribute. Code :
By videoLocator = By.id("video");
WebElement videoElement = driver.findElement(videoLocator);
String videoUrl = videoElement.getAttribute("innerHTML");
I am trying get value or text from element, but it is not working. Kindly help me in this. Below is the path and Web Element.
Link:https://www.tcsion.com/OnlineAssessment/ScientificCalculator/Calculator.html
Element:
<input id="keyPad_UserInput" class="keyPad_TextBox" maxlength="30" readonly="" type="text">
You can use following code to get value from textfield.
driver.findElement(By.id("keyPad_UserInput")).click();
String text=driver.findElement(By.id("keyPad_UserInput")).getText();
System.out.println(text);
Try this;
driver.findElement(By.id("keyPad_UserInput")).getAttribute("value")
You can use javascript executor to get value value from input field.
String return_value = (String) js.executeScript("return document.getElementById('keyPad_UserInput').value");
hope this help !
Use the below code,you will get the text entered in the field.
driver.findElement(By.xpath(".//*[#id='keyPad_btn2']")).click();
WebElement firstName = driver.findElement(By.xpath(".//*[#id='keyPad_btn2']"));
String value = firstName.getText();
System.out.println(value);
The Input Type Is Readbleonly you will get Data By using getAttribute("value") method Only
driver.get("https://www.tcsion.com/OnlineAssessment/ScientificCalculator/Calculator.html");
System.out.println(" Page");
Thread.sleep(3000);
WebElement ele = driver.findElement(By.xpath("//input[#id='keyPad_UserInput']"));
System.out.println("value using getAttribute ::"+ele.getAttribute("value"));
System.out.println("value using getText::"+ ele.getText()); //its return empty or null
OutPut :
value using getAttribute :: 0
value using getText ::
I am parsing the html from the following webpage using Jsoup. How do I get the value from the variable price_ourBase:
<script type="text/javascript">
var price_ourBase = 279;
.
.
.
</script>
JS:
Element upperContainer_inner = document.select("div.upperContainer_inner").first();
Element table = upperContainer_inner.select("table.645.0.left.0.0").first();
Element script = table.select("script").first();
Element base_ourPrice = script.select("base_ourPrice").first();
price = (?, not sure what to put here or if there is more code needed).text();
I dont think jSoup can parse javascript like that. But, you could select the contents of the script with jSoup and then you could do something like
String[] result = script.toString().split(" ");
if(result[1].equals("price_ourBase"))
System.out.println("Our price is "+result[3].split(";")[0]);
I am implement displaytag by extend the standard. Please see detail below.
JSP
display:table name="testList" id="obj" requestURI="testAction.do?pageAction=init" pagesize="${paging_size}" sort="list" class="table" **sort="external"** excludedParams="*" decorator="dyndecorator" export="false" **keepStatus="true"**
display:setProperty name="pagination.pagenumber.param" value="page"
display:setProperty name="pagination.sort.param" value="sort" /
display:setProperty name="pagination.sortdirection.param" value="dir"
display:column property="testNo" title="Test no." **sortable="true"** **sortName="testNo"**
display:column property="testValue" title="Test value" **sortable="true"** **sortName="testValue"**
display:table
PaginatedListImpl
public PaginatedListImpl(HttpServletRequest request) {
sortCriterion = request.getParameter("sort");
sortDirection = "desc".equals(request.getParameter("dir"))? SortOrderEnum.DESCENDING : SortOrderEnum.ASCENDING;
pageSize = DEFAULT_PAGE_SIZE;
String page = request.getParameter("page");
index = page == null? 0 : Integer.parseInt(page) - 1;
}
JAVA
public PaginatedListImpl getTest(
Criteria criList = session.createCriteria(TestDto.class);
criList.setFirstResult(pageDisplay.getFirstRecordIndex());
criList.setMaxResults(pageDisplay.getObjectsPerPage());
pageDisplay.setList(criList.list());
pageDisplay.setTotal((Integer) criTotal.uniqueResult());
return pageDisplay;
}
Anyway, I found problem on browser when the browser render the result
when I move the mouse over page_no. It will show "http://localhost:8080/WebProject/testAction.do?page=2&pageAction=init"
when I move the mouse over column name. It will show "http://localhost:8080/WebProject/testAction.do?sort=testValue&*dir=asc*pageAction=init"
but I need the link of both like this
"http://localhost:8080/WebProject/testAction.do?page=2&sort=testValue&dir=asc&pageAction=init"
I search on google many time but I still have a problem.
How can I do? Someone Please help me out of problem.
Thank you a lot..
I am giving you my sample code below
<%
String str = "/details.do?method=showQuestions&surveyId="+arrayNew.get(0);
%>
<html:link page='<%=str%>'><%=arrayNew.get(1)%></html:link>
Try to put url in string variable and use the string variable in the html:link tag as shown above. This may solve your problem.
Thanks