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
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
After accessing the webelements of List. Other webelement is also treated as List webelement.
List<WebElement> BrandTerms =driver.findElements(BrandTerm);
js = (JavascriptExecutor) driver;
for(int i=0;i<=1;i++)
{
js.executeScript("arguments[0].value='"+Bandtermsvalue+i + "'", BrandTerms.get(i));
}
js=null;
driver.findElements(By.id("btnAddBrandedTerms")).click();
Why is this webelement is treated as list element with message "click() is undefined for the type List"
alternatively You may extract and click on the first found
List<WebElement> BrandTerms =driver.findElements(BrandTerm);
js = (JavascriptExecutor) driver;
for(int i=0;i<=1;i++)
{
js.executeScript("arguments[0].value='"+Bandtermsvalue+i + "'", BrandTerms.get(i));
}
js=null;
driver.findElements(By.id("btnAddBrandedTerms")).get(0).click();
OR
driver.findElement(By.id("btnAddBrandedTerms")).click();
Please see webdriver API specs
https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/remote/server/handler/FindElement.html
and
https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/remote/server/handler/FindElements.html
Also highly recommending to double check selenium top tips and tricks and try that out in your project.
Hope this helps.
findElements returns a list of all the elements which match given xpath. Whereas, findElement returns first matching element using the xpath. But, be careful as if there is no element matching the given xpath, you may face exception.
To solve the issue you are facing, instead of below line:
driver.findElements(By.id("btnAddBrandedTerms")).click();
Please use this line of code:
driver.findElement(By.id("btnAddBrandedTerms")).click();
Hope it helps.
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();
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());
}
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)
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