Can anyboby help find me xpath for below ? i tried with //input[#class='new-todo ng-pristine ng-valid ng-touched'] but its not able to find it - selenium

https://todomvc.com/examples/angular2/ this is the website. and I'm trying to locate text box.
I tried with Xpath driver.findElement(By.xpath("//input[#class='new-todo ng-pristine ng-valid ng-touched']")).sendKeys("Go to GYM");
Also with driver.findElement(By.className("new-todo ng-pristine ng-valid ng-touched")).sendKeys("Blah");
But its still not able to locate element , can someone please help

//input xpath is enough
or //input[contains(#class,'new-todo')] xpath
or new-todo by class name
or .new-todo css selector
Don't forget to set some delay before accessing the element to let the page and the element completely loaded.

Related

select radio button in selenium using python

I tried
driver.find_element(By.XPATH, "//input[#value='option1']").click
But Error message generated
Note:
value attributes is not supported by find_element
ID is not available as an attribute
Below is the HTML code
label _ngcontent-c12="" class="custom-control custom-radio"
input _ngcontent-c12="" class="custom-control-input input-md input-rectangle ng-dirty ng-valid ng-touched" formcontrolname="radioBtns" name="radioBtns" nbinput="" type="radio" value="option1"
span _ngcontent-c12="" class="custom-control-description">
You'd better use find_element_by_css_selector function.
driver.find_element_by_css_selector("input[value='option1']").click()
Hope it could help.

Selenium no such element exception, unable to locate in selenium

I'm unable to use selenium in this code.By ID,Name or xpath using both.PLease tell me way to do so. how to use this in selenium . getting this error:-OpenQA.Selenium.NoSuchElementException
HResult=0x80131500
Message=no such element: Unable to locate element: {"method":"css selector","selector":"*[name =""]"}
<input id="sys_display.incident.location" name="sys_display.incident.location" aria-labelledby="label.incident.location" type="search" autocomplete="off" autocorrect="off" value="" ac_columns="u_location_code" ac_order_by="u_location_code" data-type="ac_reference_input" data-completer="AJAXTableCompleter" data-dependent="" data-dependent-value="" data-ref-qual="" data-ref="incident.location" data-ref-key="null" data-ref-dynamic="false" data-name="location" data-table="cmn_location" class="form-control element_reference_input" style="; width:240px;" spellcheck="false" onfocus="if (!this.ac) addLoadEvent(function() {var e = gel('sys_display.incident.location'); if (!e.ac) new AJAXTableCompleter(gel('sys_display.incident.location'), 'incident.location', '', ''); e.ac.onFocus();})" aria-required="true" role="combobox" aria-autocomplete="list" aria-owns="AC.incident.location" aria-expanded="false" title="" aria-invalid="false">```
It is difficult to assess without actually inspecting the DOM, but since you mentioned that the website cannot be shared; with the given input in the query, here are some of the possibilities:
Please note that these may work or may not, as I have no way to test them. They are just built using your line in the query.
There could be another possibility that your component maybe sitting in an iframe. Please check that also. If it is, then you have to first switch to iframe, and then traverse this element.
driver.find_element(By.ID, "sys_display.incident.location")
driver.find_element(By.NAME, "sys_display.incident.location")
driver.find_element(By.XPATH, "//input[#aria-labelledby='label.incident.location']")
driver.find_element(By.CSS_SELECTOR, "input[aria-labelledby='label.incident.location']")
driver.find_element(By.XPATH, "//input[#type='Search']")
driver.find_element(By.CSS_SELECTOR, "input[type='search']")
driver.find_element(By.TAG_NAME, "input")
driver.find_element(By.XPATH, "//input[#ac_columns='u_location_code']")
driver.find_element(By.XPATH, "//input[#role='combobox']")
driver.find_element(By.CSS_SELECTOR, "input[role='combobox']")

How to locate the input tag as per the HTML provided through Selenium?

Please what locator do i use for the below. I have tried Xpath and CSS Selector but no luck.
<input type="password"
class="input-block-level ng-dirty ng-valid ng-valid-required"
placeholder="Password" ng-model="password" ng-trim="false"
required="" ng-disabled="isLogging"
ng-hide="changePassword" autocomplete="off">
As per the HTML you can use either of the following solution:
CSS_SELECTOR:
"input.input-block-level.ng-dirty.ng-valid.ng-valid-required[ng-model='password']"
XPATH:
"//input[#class='input-block-level ng-dirty ng-valid ng-valid-required' and #ng-model='password']"
Note: The element is an Angular element, ensure that you interact with the element inducing WebDriverwait.
For style class ng-dirty ng-valid ng-valid-required are inserted automatically by angular compiler after angular complete compile the source code. So your locator should not rely on these style class.
1) Using Java as script language
driver.findElement(By.cssSelector("input[placeholder='Password']"))
// or
driver.findElement(By.xpath("//input[#placeholder='Password']"))
2) Using python as script language
dirver.find_element_by_css_selector("input[placeholder='Password']")
// or
driver.find_element_by_xpath("//input[#placeholder='Password']")

Not able to identify custom checkbox element/Need relative xpath

I need relative xpath of the span element
<span class="icon"></span>
in selenium web driver.
<span class="custom-checkbox">
<input id="personalization1" name="personalization-terms-check" class="personalization-terms-check required" value="accept" type="checkbox">
<label for="personalization1">
<span class="icon"></span>
<span class="order-ready-text">yes! I double-checked all personalization entered above and i'm ready to order</span>
</label>
</span>
need relative xpath of the span element
<span class="icon">
in above html and I am getting relative path:
//*[#id="main"]/div[3]/div[4]/div[2]/div/span/label/span[1].
Please help me to get an relative xpath or another way to make an click on the span
NOTE:
<span class="icon">
It can be multiple so I need unique relative xpath.
You can wait for the element visibility before performing any action like below.
WebElement element=driver.findElement(By.xpath("//*[#name='personalization-terms-check']/following-sibling::label/span"));
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.visibilityOf(element));
element.click();
and you can use different xpath or id to locate the element. the above xpath map be unique if only one personalization term checkbox on the page.
Can you try with this xpath?
"//label[#for='personalization1']/span[1]"
Hope this helps. Thanks.
Try this:
Try this XPath -
//input[#id='personalization1']/label/span
Try this xpath to click on checkbox:
.//input[#id='personalization1']
or you can use this xpath
.//span[contains(text(),'yes! I dou')]

Find element by XPath isn't working in selenium

I'm trying to find a element in selenium with this XPATH /html/body/div[3]/div/div/div[2]/div[2]/div/div/div[1]/form/div/input.
I copied it from inspect element, and copy xpath. I saw that some persons with the same problem use "*" character but I don't know where I should to use it.
this the html code
<input type="text" data-bind="value: CorpItem.Name, valueUpdate: 'afterkeydown'"
class="form-control" placeholder="Enter ..." required="required">
Here is my code on Selenium
IWebElement corpName = driver.FindElement(By.CssSelector("/html/body/div[3]/div/div/div[2]/div[2]/div/div/div[1]/form/div/input"))
Try this XPath
//input[#type='text'][#class='form-control']
In your code you used XPath and gave selector as CSS. Please verify.
Using your XPath, your code must be
IWebElement corpName = driver.FindElement(By.XPath("/html/body/div[3]/div/div/div[2]/div[2]/div/div/div[1]/form/div/input"))
If it didn't work, try
IWebElement corpName = driver.FindElement(By.XPath("//input[#type='text'][#class='form-control']"));