Html code is:
**p style="width: 46%;" xpath="1"
input ng-disabled="true" type="text" class="EOR-btn ng-pristine ng-valid" name="eor" id="eor" ng-model="vm.EOR" placeholder="" style="width: 96%;" disabled="disabled"
/p**
** Invoice number : 350971854 **
how to find Xpath, copy invoice number. And paste in Excel.
find xpath try to
driver.findElement(By.Xpath("//input[#id='eor']").getText();
input given me null? So I need to copy Invoice number.
driver.findElement(By.xpath(//p[#id='eor']).getText();
Try this
Related
Query 1:
I would request you to please help me on getting xpath for submit button. Absolute path starts with Select file and *.
<div id="bg">
<label id="label" style=" font-family: Segoe UI;color:#2e2e2e; font-size:12px; float:left; padding-top:8px;">
Select File <span id="spanhide" class="red">*</span></label>
<div style="margin-left:105px;"><input type="file" name="filUploadIcon" id="filUploadIcon" class="txt-box" onchange="FileUpload_OnChange(this,event);" style="width:180px;">
<input type="submit" name="btnUploadcancel" value="" onclick="return check();" id="btnUploadcancel" title="Upload" class="upload_pop"></div>
<input name="textFileName" type="text" id="textFileName" style="display:none;">
<input type="hidden" name="hdnframeID" id="hdnframeID">
<input type="hidden" name="hdnlbl" id="hdnlbl">
</div>
Query 2:
How to write xpath to skip few nodes in between. Please help. Also let me know adding // or * in between to skip nodes.
Ex: Above HTML
//*div[#id="bg"]/skip elements before input type submit node/input [#type="submit"]
Use the below xpath to target the precedence nodes that include the label with the string "Select File" and the embedded span that contains '*'.
//div[contains(#id, 'bg')]/label[contains(text(), 'Select File')]/span[contains(text(), '*')]
Then add on the below line to return to the parent node label to the span tag.
/parent::label
Then add on the below to get to the sibling div tag of the label tag, which contains the input tag with a type of submit.
/following-sibling::div/input[#type='submit']
So the xpath in its entirety should look like this:
//div[contains(#id, 'bg')]/label[contains(text(), 'Select File')]/span[contains(text(), '*')]/parent::label/following-sibling::div/input[#type='submit']
You can use below xpath.
//div[#id='bg']//input[#name='btnUploadcancel']
Strongly suggest to go through this to learn more on xpath 1.0 which will answer all your questions in OP.
Using Selenium Webdriver and Java, I want to select a option from the list which is displayed inside 'input' tag instead of 'Select' tag.
Please find below details-
The GUI is as following-
Please find the GUI image here
<td nowrap="" valign="middle" colspan="3" rowspan="1">
<div class="mceGridField siebui-value mceField">
<input type="text" name="s_6_2_158_0" value="" aria-labelledby="BGC_Type_Label" aria-label="Type" style="height: 24px; width:80px;" class="siebui-ctrl-select siebui-input-popup siebui-align-left siebui-input-align-left ui-autocomplete-input" aria-describedby=" s_6_2_158_0_icon" maxlength="30" tabindex="0" role="combobox" autocomplete="off" data-seq="0" aria-readonly="false">
<span class="siebui-icon-dropdown applet-form-combo applet-list-combo" id="s_6_2_158_0_icon" data-allowdblclick="true"></span></div>
</td>
The GUI List of options are as following-
Please find the GUI image of option list after clicking
I am using below code to select one of the option from the list-
driver.findElement(By.xpath("//*[#id='s_6_2_158_0_icon']")).click();
But still I am not able to select any option.
Can you please help ?
To invoke click() on the desired option from the list you need to induce WebDriverWait for the desired element to be clickable and you can use the following solution:
cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input[name^='s_'][aria-labelledby='BGC_Type_Label'][aria-label='Type']"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[starts-with(#name,'s_')][#aria-labelledby='BGC_Type_Label' and #aria-label='Type']"))).click();
Did you try sendKeys method btw-
driver.findElement(By.xpath("//*[#id='s_6_2_158_0_icon']")).sendKeys("Fix");
And it's better to use the id -
driver.findElement(By.name("s_6_2_158_0_icon")).sendKeys("Fix");
Please help me to find locator in this case as id is dynamic and it changes every time when I refresh the page.
type="text" also I will not be able to use because, for the next fields, eveything is same from the down code except, the label changes from the "first name" to the "last name" and so on.
So I should be selecting something in terms of the first name which is mentioned in the label tag below.
Please anyone can help me in this case.
<input class="md-input-element ng-valid ng-dirty ng-touched" id="md-
input-4-input" spellcheck="false" type="text">
<!--template bindings={}-->
<label class="md-input-placeholder md-float md-empty" for="md-input-
4-input">First name * <!--template bindings={}--></label>
You can use preceding-sibling or following-sibling feature from xpath. As per code mentioned above your xpath should be like this:
//input[#type='text'][following-sibling::label[contains(text(),'First name')]]
But I think in html label should be first then input, if that is case please try below one:
//input[#type='text'][preceding-sibling::label[contains(text(),'First name')]]
you can get the css selector from the class (can't do by className if it has spaces in the class name so use css, put a "." at the beginning and replace any spaces with a ".")
#FindBy(css = ".md-input-element.ng-valid.ng-dirty.ng-touched")
private WebElement elementMDInputTouched;
#FindBy(css = ".md-input-placeholder.md-float.md-empty")
private WebElement elementMDInputEmpty;
How to locate the element below in Selenium?
<input id="mainForm:field_LayFact450505264_16032015_145612--Order-ServiceClass_R" class="iceSelInpTxtTxt fieldTxt" type="text" value="" style="width: 150px;" onmousedown="this.focus();" onfocus="setFocus(this.id);svOnFocus(formOf(this), this, event, false);" onblur="setFocus('');svOnBlur(formOf(this), this, event);" name="mainForm:field_LayFact450505264_16032015_145612--Order-ServiceClass_R" autocomplete="off">
I tried with ends-with, it did not work.
You can use the below
WebElement inputClass = driver.findElement(By.className("iceSelInpTxtTxt fieldTxt"));
WebElement Element = driver.findElement(By.xpath("Try any Below xpaths"))
If your input id is unique then use below xpath
//input[#id='mainForm:field_LayFact450505264_16032015_145612--Order-ServiceClass_R']
OR
//input[#name='mainForm:field_LayFact450505264_16032015_145612--Order-ServiceClass_R']
OR if the combination of both of id and name make them unique then use below xpath
//input[#name='mainForm:field_LayFact450505264_16032015_145612--Order-ServiceClass_R' and #id='mainForm:field_LayFact450505264_16032015_145612--Order-ServiceClass_R']
OR
//input[#class='iceSelInpTxtTxt fieldTxt']
Hope it will help you :)
I want to get text "Entered code is already exists" using selenium webdriver , I tried using id="code_error" but no use
HTML code is as follows :
<div class="leftsection">
<div class="form-element">
<fieldset>
<label><span class="required">*</span>Code:</label>
<input type="text" maxlength="6" value="" id="code" name="code" style="border: 1px solid rgb(178, 178, 178);">
</fieldset>
<span role="alert" class="errormsg" id="code_error">Entered Code already exists</span>
</div>
i used xpath , id, cssselecor but it returns NULL.
Have a look at the below code..works perfectly
options=driver.find_elements_by_class_name("errormsg")
for i in options:
print i.text
when selenium can parse JavaScript, you can use this:
var text = document.getElementById('sbucode_error').innerHTML;
Please use Selenium Ide to check whether id=code_error selector pointing to your element then use the below mentioned code to get text from that.
driver.findElement(By.id("code_error")).getText();
String text = driver.findElementById("code_error").getText(); should do the trick for you :)