WebDriver:: getText() fetches only partial String [closed] - selenium

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am trying to read the below html code using getText() {Selenium-WebDriver}, this is my locator and script line
#FindBy(xpath="//p[#class='radiobutton']") WebElement groupMsg;
System.out.println("This is the group message"+groupMsg.getText()); //msg display on console
o/p on console :: This is the group messageRadio button 'Male' is checked
As i showed its showing only "Sex : Male". not getting the "Age group: 5 - 15". Its happening because of (i think Pl correct me if i am wrong)
<p class="groupradiobutton">
Sex : Male
<br>
Age group: 5 - 15
</p>
Can any one give solution for this?

Below code is workig.
String a=driver.findElement(By.className("groupradiobutton")).getText();
System.out.Println(a);
This is printing the output as below in console.
Sex : Male
Age group: 5 - 15
I have tested with the html you have given.

Use below code
driver.findElement(By.xpath("//p[#class='groupradiobutton')).getText();

Related

Xpath element not found [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
I can't find my link using this Xpath //a[contains(text(),'My stuff')]
Though I can find it through DOM :
HTML :
<li _ngcontent-c8="">
<a _ngcontent-c8="" href="my-stuff">
{" "}
My Stuff{" "}
</a>
</li>;
When executed :
try:
my_stuff = WebDriverWait(driver, 8).until(
EC.presence_of_element_located((By.XPATH, "//a[contains(text(),'My stuff')]"))
)
my_stuff.click()
except:
print("not found")
returns not found
There was a modal messing with my selection that needed to be dissmissed.
i will try to analyse the problem and give you most answer
. first : if you have Xpath Helper "google chrome extension" try to put your Xpath there
=> if you find it then the problem in your code . we will try to change it
=> if you can't find it with Xpath helper ,than there is multiple choice:
first try to find if there is a "table" or new "form" above your Xpath , that you can't get it with absolute path
. you must get inside the "table" or "form", then find the path inside it
, tell me if that didn't work

How to handle multi select list box using selenium? [duplicate]

This question already has answers here:
How to select multiple options from multi select list using Selenium-Python?
(4 answers)
Closed 3 years ago.
Help me with selenium commands/code to fetch the data from the list. We can only select the data from the list, since entering text(like auto search) is not allowed.
I have used the following code, but couldn't resolve the issue. Also I have doubt regarding which xpath given Do I need to give the xpath of the input field or the drop down list?
*WebElement mySelectElement = driver.findElement(By.xpath("//*[#id='basicBootstrapForm']/div[7]/div/multi-select"));
Select dropdown= new Select(mySelectElement);
dropdown.selectByValue("Arabic");
dropdown.selectByIndex(2);
dropdown.selectByVisibleText("Catalan");*
You need to first click on the dropdwon box and then find out the elemnet you are looking for and then click.Hope this help you.Let me know if this work
driver.findElement(By.id("msdd")).click();
List<WebElement> languages=driver.findElements(By.xpath("//a[#class='ui-corner-all']"));
for(int i=0;i<languages.size();i++)
{
System.out.println(languages.get(i).getText());
if(languages.get(i).getText().equalsIgnoreCase("Arabic"))
{
languages.get(i).click();
break;
}
}

Selenium xpath each element 5 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I use selenium and xpath selector. I know how to get a certain element. But how to use xpath to get each element 5?
You can always solve it in your language of choice.
Python
For example, in Python, the extended slicing allows to do it rather simply:
driver.find_elements_by_xpath("//table/tr")[0::5]
You can also use the position() function and the mod operator:
//table/tr[position() mod 5 = 0]
driver.find_elements_by_xpath("//table/tr[position() mod 5 = 0]")
Java
List<WebElement> elements=driver.findElements(By.xpath("//tbody/tr[position() mod 5 = 0]"));
System.out.println(elements.size());
for (WebElement element : elements) {
System.out.println(element.getText());
}

Robot Framework: How to clear the text in Textfield [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I want to know that how to remove the text from Textbox. I have did much search from Google but nothing found currently. Please tell me any Keyword which can help me for remove/clean text in field.
You can use this also for clear test field..
driver.findElement(By.id("textfieldid")).sendKeys("");//empty string
or
Input Text (your web element locator ) ${empty}
You don't need a Robot to do it.. Just use Selenium.
driver.findElement(By.id("username")).clear();
http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebElement.html#clear()
You don't need it. Check here
def input_text(self, locator, text):
"""Types the given `text` into text field identified by `locator`.
See `introduction` for details about locating elements. """
self._info("Typing text '%s' into text field '%s'" % (text, locator))
self._input_text_into_text_field(locator, text)
The Input Text keyword is calling the
_input_text_into_text_field
which is anyway sending the clear command:
def _input_text_into_text_field(self, locator, text):
element = self._element_find(locator, True, True)
element.clear()
element.send_keys(text)

VBA getElementById not working [duplicate]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
document.getElementById('id of div that definately exists') returns null.
I originally loaded the javascript last in order to make sure I wouldn't need to worry about the onload event. I also tried using the onload event. It's very spooky. Any ideas or help would be greatly appreciated.
Also be careful how you execute the js on the page. For example if you do something like this:
(function(window, document, undefined){
var foo = document.getElementById("foo");
console.log(foo);
})(window, document, undefined);
This will return null because you'd be calling the document before it was loaded.
Better option..
(function(window, document, undefined){
// code that should be taken care of right away
window.onload = init;
function init(){
// the code to be called when the dom has loaded
// #document has its nodes
}
})(window, document, undefined);
It can be caused by:
Invalid HTML syntax (some tag is not closed or similar error)
Duplicate IDs - there are two HTML DOM elements with the same ID
Maybe element you are trying to get by ID is created dynamically (loaded by ajax or created by script)?
Please, post your code.
There could be many reason why document.getElementById doesn't work
You have an invalid ID
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
(resource: What are valid values for the id attribute in HTML?)
you used some id that you already used as <meta> name in your header (e.g. copyright, author... ) it looks weird but happened to me: if your 're using IE take a look at
(resource: http://www.phpied.com/getelementbyid-description-in-ie/)
you're targeting an element inside a frame or iframe. In this case if the iframe loads a page within the same domain of the parent you should target the contentdocument before looking for the element
(resource: Calling a specific id inside a frame)
you're simply looking to an element when the node is not effectively loaded in the DOM, or maybe it's a simple misspelling
I doubt you used same ID twice or more: in that case document.getElementById should return at least the first element