Below are separate textboxt1 IDs for getting the text:
WebElement Text = driver.findElement(By.id("incident.number"));
String result = Text.getText();
How can I write the code for getting the values from gettext?
Below are textbox2 id:
driver.findElement(By.id("38240a5edb5912000c91d540cf9619b9_text"));
I want to get the value from textbox1 to textbox2. How can I get the attributes from getText?
You can get the the value of text box using getAttribute("value") like driver.findElement(By.id("38240a5edb5912000c91d540cf9619b9_text")).getAttribute("value"). This will return you the value of a textbox.
You can get the string in the textbox by getAttribute("value"):
String textboxValue = driver.findElement(By.id("38240a5edb5912000c91d540cf9619b9_text")).getAttribute("value");
If you are able to get the value from the textbox, then just pass that string to textbox2 using sendKeys as below.
driver.findElement(By.id("38240a5edb5912000c91d540cf9619b9_text")).sendKeys(result);
I am supposing that the locator is fine and able to locate the elements.
Related
I want to validate a text but its in Hindi in the website i am working on .
The code goes this way
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.textToBePresentInElementLocated(
By.xpath("/html/body/nav[1]/div/ul/div/div/li[2]/form/input[4]"),
"हिंदी"));
System.out.println("Language changed to "+ landingpage.getHindiLanguage().getText());
And The Output I Get is
Expected condition failed: waiting for text ('?????') to be present in element found by By.xpath:
How shall i approach this?
From your xpath assuming you are trying to getText from a input tag
Input tag stores the value in value attribute so you should get the value from the attribute instead of using getText() use
webelement.getAttribute("value") this will return values stored in input field
getText() will works only for HTML element which store values in node.
Like p tag as shown below
<p>PARAGRAPH</p>
I'm trying to access the name of different products displayed on a website using selenium. For example on https://www.supremenewyork.com/shop/all/jackets i'm able to locate the products (webElements) and put them in a list but I can't get their name (as displayed under the image). Is there a way to do this using Selenium (in java)?
I have tried most of the methods in the WebElement Interface's API.
driver.get("https://www.supremenewyork.com/shop/all/");
ArrayList <WebElement> list = new ArrayList<>();
list.addAll(driver.findElements(By.className("inner-article")));
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i).getTagName());
}
i would expect a console output displaying the names of all the product of the page However i get a list of the same string : "div".
You have to use .getText(). replace the line to
System.out.println(list.get(i).getText());
Selenium docs state that
"Get the tag name of this element. Not the value of the name attribute: will return "input" for the element ."
If you are trying to get the name attribute. You should try
System.out.println(list.get(i).getAttribute("name"));
Name can be changed for any other attribute that you want.
You could try using getText() method, according to documentation it will return all of visible text from the element and all subelements. If you need only product name or color, try using By.ByCssSelector(String cssSelector) and specify selector as ".inner-article p a" for color or ".inner-article h1 a" for name when selecting elements.
I am completely new to selenium. I am using Selenium and java.The following is my resulting screen value. I want to select the double quoted data(Test) from this screen, and i want to replace it to a different value.
"value": "Test",**
"createDateTime": "2016-08-23T15:37:06+0100",
"channel": "POST",
Note: the whole data is under a div class =ace_gutter, the parent div class is "aceEditor".
After a long struggle i found the following xpath for that row which i want to get the value from.
HTML code:
#11
Xpath:
It is this
[#id='aceEditor']/div[1]/div[1]/div[11].
myCode:
String value= driver1.findElement(By.xpath("//*[#id='aceEditor']/div[1]/div[1]/div[11]")).getAttribute("innerHTML") ;
It is giving 11, instead of the actual text("value": "Test",)from the screen. Could any one Please help me with the code. I have searched enough i am not finding any solution.
To replace the value in the HTML page, you will have to use the executeScript method.
String replace_text = "Text to be replaced";
js = ((JavascriptExecutor) driver)
js.executeScript("return document.getElementById('<id of the element>').innerHTML='" + replace_text + "';");
I am creating an automatic test for some webs and I'm using WebDriver, TestNG and code that is written in Java. On the page is shown register of categories, in parentheses is number of auctions and i need to get this number as variable, but i don't know, how.
I use the following code:
WebElement number1_1_vse = (driver.findElement(By.linkText("Vše")));
String text_vse1_1 = number1_1_vse.getText();
but output is only: "Vše" without (number of auctions)
link to the website
screenshot -> image with the number
can anyone advise me please?
With linktext you are finding the nested a which text is Vše only. You need to find the li containing the text Vše (949)
Use the following css selector to identify the element
By bycss =By.cssSelector(".list.list-categories>li:first-child");
WebElement number1_1_vse = driver.findElement(bycss );
String text_vse1_1 = number1_1_vse.getText();
WebElement parent = number1_1_vse.findElement(By.xpath(".."));
// which will give you access to <li>
List<WebElement> childs = parent.findElements(By.xpath(".//*"));
// childs.get(1) has the result.
Please try to get the xpath value and then try to search it with below mentioned syntax :
findelementbyxpath("//*[#id="post-form"]/h2")
To get xpath value of and element : right click --> inspect element --> right click copy xpath
I have a WebElement containing link found by url. I can extract url by:
element.getAttribute("href");
But the question is: how to extract it's anchor, I'm trying like this:
webElement.getAttribute("linkText");
It gives me null value. I'm 100% sure this link has an anchor. Is there any way to get anchor ? It's more complicated, but example simplified code could look like this:
WebDriver driver = new FirefoxDriver();
driver.get("http://stackoverflow.com/questions/tagged/java");
WebElement link = driver.findElement(By.linkText("Bicycles"));
System.out.println(link.getAttribute("href")); // shows http://bicycles.stackexchange.com/
System.out.println(link.getAttribute("linkText")); // shows null
Try this:
System.out.println(link.getText());
If getText() returns an empty String, try the innerHTML attribute:
String text = element.getAttribute("innerHTML")
By "Anchor" I think you mean the text of the link? If so, then you can use .getText() since an <a> is a block level element.
link.getText();
Here you can store your id text:
String text = driver.findElement(By.id("Text")).getText();
System.out.println(text);