Forum Discussion

tvklovesu's avatar
tvklovesu
Frequent Contributor
12 months ago
Solved

Object not found when using FindElement(xpath) with a Parent object

Hello,

I am seeing this issue for a long time but never thought of fixing it as I used some other solutions. So, when I try to use Findelement with a parent object and use xpath then the object under that parent is not selected. I need to use CSS in FindElement instead of Xpath, then only it will find the element that is under that parent. but here I cannot use CSS

 

I am trying to do a property check and the syntax is.

Aliases.browser.RavenDarttsPge.Highlight_Quantity_section = "//label[contains(.,'Highlight quantity discrepancies')]"

Aliases.browser.RavenDarttsPge.Highlight_Quantity_section.findElement("//following-sibling::div//div[@aria-label='greater or less than']")

 

But it's identifying the first element that's under "Highlight value discrepancies".

Attached is the source code of those elements and the screenshot

 

 

<div class="MuiGrid-root MuiGrid-item MuiGrid-grid-sm-12">
	<label class="MuiFormControlLabel-root">
		<span class="MuiButtonBase-root MuiIconButton-root jss114 MuiCheckbox-root MuiCheckbox-colorPrimary jss115 Mui-checked MuiIconButton-colorPrimary" aria-disabled="false" aria-label="check-box-Highlight value discrepancies">
			<span class="MuiIconButton-label">
				<input class="jss117" name="Highlight value discrepancies" type="checkbox" data-indeterminate="false" value="" checked="">
				</span>
				<span class="MuiTouchRipple-root"></span>
			</span>
			<span class="MuiTypography-root MuiFormControlLabel-label MuiTypography-body1">Highlight value discrepancies</span>
		</label>
		<div class="MuiBox-root jss118 jss111">
			<div class="MuiBox-root jss119 jss112">
				<div role="group" class="MuiToggleButtonGroup-root jss113" aria-label="greater or less than">
					<button class="MuiButtonBase-root MuiToggleButton-root MuiToggleButtonGroup-grouped MuiToggleButtonGroup-groupedHorizontal MuiToggleButton-sizeSmall" tabindex="0" type="button" value="less" aria-pressed="false" color="primary" aria-label="less than">
						<span class="MuiToggleButton-label">
							<svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeSmall" focusable="false" viewBox="0 0 24 24" aria-hidden="true" title="less than">
								<path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"></path>
							</svg>
						</span>
						<span class="MuiTouchRipple-root"></span>
					</button>
					<button class="MuiButtonBase-root MuiToggleButton-root MuiToggleButtonGroup-grouped MuiToggleButtonGroup-groupedHorizontal Mui-selected MuiToggleButton-sizeSmall" tabindex="0" type="button" value="greater" aria-pressed="true" color="primary" aria-label="greater than">
						<span class="MuiToggleButton-label">
							<svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeSmall" focusable="false" viewBox="0 0 24 24" aria-hidden="true" title="greater than">
								<path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"></path>
							</svg>
						</span>
						<span class="MuiTouchRipple-root"></span>
					</button>
				</div>
				<div class="MuiFormControl-root MuiTextField-root MuiFormControl-fullWidth">
					<label class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-marginDense MuiInputLabel-outlined MuiFormLabel-filled" data-shrink="true" for="absolute" id="absolute-label">Absolute threshold</label>
					<div class="MuiInputBase-root MuiOutlinedInput-root MuiInputBase-fullWidth MuiInputBase-formControl MuiInputBase-adornedStart MuiOutlinedInput-adornedStart MuiInputBase-adornedEnd MuiOutlinedInput-adornedEnd MuiInputBase-marginDense MuiOutlinedInput-marginDense">
						<div class="MuiInputAdornment-root MuiInputAdornment-positionStart MuiInputAdornment-marginDense">
							<p class="MuiTypography-root MuiTypography-body1 MuiTypography-colorTextSecondary">$</p>
						</div>
						<input aria-invalid="false" id="absolute" type="number" class="MuiInputBase-input MuiOutlinedInput-input MuiInputBase-inputAdornedStart MuiOutlinedInput-inputAdornedStart MuiInputBase-inputAdornedEnd MuiOutlinedInput-inputAdornedEnd MuiInputBase-inputMarginDense MuiOutlinedInput-inputMarginDense" value="100000">
							<div class="MuiInputAdornment-root MuiInputAdornment-positionEnd MuiInputAdornment-marginDense">
								<p class="MuiTypography-root MuiTypography-body1 MuiTypography-colorTextSecondary"></p>
							</div>
							<fieldset aria-hidden="true" class="jss107 MuiOutlinedInput-notchedOutline">
								<legend class="jss109 jss110">
									<span>Absolute threshold</span>
								</legend>
							</fieldset>
						</div>
					</div>
				</div>
				<div class="MuiBox-root jss120 jss112">
					<div role="group" class="MuiToggleButtonGroup-root jss113" aria-label="greater or less than">
						<button class="MuiButtonBase-root MuiToggleButton-root MuiToggleButtonGroup-grouped MuiToggleButtonGroup-groupedHorizontal MuiToggleButton-sizeSmall" tabindex="0" type="button" value="less" aria-pressed="false" color="primary" aria-label="less than">
							<span class="MuiToggleButton-label">
								<svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeSmall" focusable="false" viewBox="0 0 24 24" aria-hidden="true" title="less than">
									<path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"></path>
								</svg>
							</span>
							<span class="MuiTouchRipple-root"></span>
						</button>
						<button class="MuiButtonBase-root MuiToggleButton-root MuiToggleButtonGroup-grouped MuiToggleButtonGroup-groupedHorizontal Mui-selected MuiToggleButton-sizeSmall" tabindex="0" type="button" value="greater" aria-pressed="true" color="primary" aria-label="greater than">
							<span class="MuiToggleButton-label">
								<svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeSmall" focusable="false" viewBox="0 0 24 24" aria-hidden="true" title="greater than">
									<path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"></path>
								</svg>
							</span>
							<span class="MuiTouchRipple-root"></span>
						</button>
					</div>
					<div class="MuiFormControl-root MuiTextField-root MuiFormControl-fullWidth">
						<label class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-marginDense MuiInputLabel-outlined MuiFormLabel-filled" data-shrink="true" for="percent" id="percent-label">Percentage threshold</label>
						<div class="MuiInputBase-root MuiOutlinedInput-root MuiInputBase-fullWidth MuiInputBase-formControl MuiInputBase-adornedEnd MuiOutlinedInput-adornedEnd MuiInputBase-marginDense MuiOutlinedInput-marginDense">
							<input aria-invalid="false" id="percent" type="number" class="MuiInputBase-input MuiOutlinedInput-input MuiInputBase-inputAdornedEnd MuiOutlinedInput-inputAdornedEnd MuiInputBase-inputMarginDense MuiOutlinedInput-inputMarginDense" value="20">
								<div class="MuiInputAdornment-root MuiInputAdornment-positionEnd MuiInputAdornment-marginDense">
									<p class="MuiTypography-root MuiTypography-body1 MuiTypography-colorTextSecondary">%</p>
								</div>
								<fieldset aria-hidden="true" class="jss107 MuiOutlinedInput-notchedOutline">
									<legend class="jss109 jss110">
										<span>Percentage threshold</span>
									</legend>
								</fieldset>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="MuiGrid-root MuiGrid-item MuiGrid-grid-sm-12">
				<label class="MuiFormControlLabel-root">
					<span class="MuiButtonBase-root MuiIconButton-root jss114 MuiCheckbox-root MuiCheckbox-colorPrimary MuiIconButton-colorPrimary" aria-disabled="false" aria-label="check-box-Highlight quantity discrepancies">
						<span class="MuiIconButton-label">
							<input class="jss117" name="Highlight quantity discrepancies" type="checkbox" data-indeterminate="false" value="">
								
							</span>
							<span class="MuiTouchRipple-root"></span>
						</span>
						<span class="MuiTypography-root MuiFormControlLabel-label MuiTypography-body1">Highlight quantity discrepancies</span>
					</label>
					<div class="MuiBox-root jss121 jss111">
						<div class="MuiBox-root jss122 jss112">
							<div role="group" class="MuiToggleButtonGroup-root jss113" aria-label="greater or less than">
								<button class="MuiButtonBase-root MuiToggleButton-root MuiToggleButtonGroup-grouped MuiToggleButtonGroup-groupedHorizontal Mui-disabled MuiToggleButton-sizeSmall Mui-disabled" tabindex="-1" type="button" disabled="" value="less" aria-pressed="false" color="primary" aria-label="less than">
									<span class="MuiToggleButton-label">
										<svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeSmall" focusable="false" viewBox="0 0 24 24" aria-hidden="true" title="less than">
											<path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"></path>
										</svg>
									</span>
								</button>
								<button class="MuiButtonBase-root MuiToggleButton-root MuiToggleButtonGroup-grouped MuiToggleButtonGroup-groupedHorizontal Mui-disabled Mui-selected MuiToggleButton-sizeSmall Mui-disabled" tabindex="-1" type="button" disabled="" value="greater" aria-pressed="true" color="primary" aria-label="greater than">
									<span class="MuiToggleButton-label">
										<svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeSmall" focusable="false" viewBox="0 0 24 24" aria-hidden="true" title="greater than">
											<path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"></path>
										</svg>
									</span>
								</button>
							</div>
							<div class="MuiFormControl-root MuiTextField-root MuiFormControl-fullWidth">
								<label class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-marginDense MuiInputLabel-outlined Mui-disabled Mui-disabled MuiFormLabel-filled" data-shrink="true" for="absolute" id="absolute-label">Absolute threshold</label>
								<div class="MuiInputBase-root MuiOutlinedInput-root Mui-disabled Mui-disabled MuiInputBase-fullWidth MuiInputBase-formControl MuiInputBase-adornedStart MuiOutlinedInput-adornedStart MuiInputBase-adornedEnd MuiOutlinedInput-adornedEnd MuiInputBase-marginDense MuiOutlinedInput-marginDense">
									<div class="MuiInputAdornment-root MuiInputAdornment-positionStart MuiInputAdornment-marginDense">
										<p class="MuiTypography-root MuiTypography-body1 MuiTypography-colorTextSecondary"></p>
									</div>
									<input aria-invalid="false" disabled="" id="absolute" type="number" class="MuiInputBase-input MuiOutlinedInput-input Mui-disabled Mui-disabled MuiInputBase-inputAdornedStart MuiOutlinedInput-inputAdornedStart MuiInputBase-inputAdornedEnd MuiOutlinedInput-inputAdornedEnd MuiInputBase-inputMarginDense MuiOutlinedInput-inputMarginDense" value="10000">
										<div class="MuiInputAdornment-root MuiInputAdornment-positionEnd MuiInputAdornment-marginDense">
											<p class="MuiTypography-root MuiTypography-body1 MuiTypography-colorTextSecondary"></p>
										</div>
										<fieldset aria-hidden="true" class="jss107 MuiOutlinedInput-notchedOutline">
											<legend class="jss109 jss110">
												<span>Absolute threshold</span>
											</legend>
										</fieldset>
									</div>
								</div>
							</div>
							<div class="MuiBox-root jss123 jss112">
								<div role="group" class="MuiToggleButtonGroup-root jss113" aria-label="greater or less than">
									<button class="MuiButtonBase-root MuiToggleButton-root MuiToggleButtonGroup-grouped MuiToggleButtonGroup-groupedHorizontal Mui-disabled MuiToggleButton-sizeSmall Mui-disabled" tabindex="-1" type="button" disabled="" value="less" aria-pressed="false" color="primary" aria-label="less than">
										<span class="MuiToggleButton-label">
											<svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeSmall" focusable="false" viewBox="0 0 24 24" aria-hidden="true" title="less than">
												<path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"></path>
											</svg>
										</span>
									</button>
									<button class="MuiButtonBase-root MuiToggleButton-root MuiToggleButtonGroup-grouped MuiToggleButtonGroup-groupedHorizontal Mui-disabled Mui-selected MuiToggleButton-sizeSmall Mui-disabled" tabindex="-1" type="button" disabled="" value="greater" aria-pressed="true" color="primary" aria-label="greater than">
										<span class="MuiToggleButton-label">
											<svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeSmall" focusable="false" viewBox="0 0 24 24" aria-hidden="true" title="greater than">
												<path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"></path>
											</svg>
										</span>
									</button>
								</div>
								<div class="MuiFormControl-root MuiTextField-root MuiFormControl-fullWidth">
									<label class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-marginDense MuiInputLabel-outlined Mui-disabled Mui-disabled MuiFormLabel-filled" data-shrink="true" for="percent" id="percent-label">Percentage threshold</label>
									<div class="MuiInputBase-root MuiOutlinedInput-root Mui-disabled Mui-disabled MuiInputBase-fullWidth MuiInputBase-formControl MuiInputBase-adornedEnd MuiOutlinedInput-adornedEnd MuiInputBase-marginDense MuiOutlinedInput-marginDense">
										<input aria-invalid="false" disabled="" id="percent" type="number" class="MuiInputBase-input MuiOutlinedInput-input Mui-disabled Mui-disabled MuiInputBase-inputAdornedEnd MuiOutlinedInput-inputAdornedEnd MuiInputBase-inputMarginDense MuiOutlinedInput-inputMarginDense" value="20">
											<div class="MuiInputAdornment-root MuiInputAdornment-positionEnd MuiInputAdornment-marginDense">
												<p class="MuiTypography-root MuiTypography-body1 MuiTypography-colorTextSecondary">%</p>
											</div>
											<fieldset aria-hidden="true" class="jss107 MuiOutlinedInput-notchedOutline">
												<legend class="jss109 jss110">
													<span>Percentage threshold</span>
												</legend>
											</fieldset>
										</div>
									</div>
								</div>
							</div>
						</div>

 

I need to find the element under Quantity discrepancies

TIA

 

  • Hi,

     

    I am not a fan of XPath in TestComplete world and thus don't remember exact syntax, but of top of my head:

    -- Double slash at the start of XPath effectively commands XPath engine to search from the top of the page;

    -- XPath must start with dot and slash to command XPath engine to search from the current element (i.e. something like that, if I am not mistaken: ./label[contains(.,'Highlight quantity discrepancies')]");

    -- If my above two statements are correct, than this your syntax looks to be correct:

    Aliases.browser.RavenDarttsPge.Highlight_Quantity_section.findElement("./following-sibling::div//div[@aria-label='greater or less than']")

     

    P.S. Hope, my statements are correct as per this: https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ms256086(v=vs.100)

     

2 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    I am not a fan of XPath in TestComplete world and thus don't remember exact syntax, but of top of my head:

    -- Double slash at the start of XPath effectively commands XPath engine to search from the top of the page;

    -- XPath must start with dot and slash to command XPath engine to search from the current element (i.e. something like that, if I am not mistaken: ./label[contains(.,'Highlight quantity discrepancies')]");

    -- If my above two statements are correct, than this your syntax looks to be correct:

    Aliases.browser.RavenDarttsPge.Highlight_Quantity_section.findElement("./following-sibling::div//div[@aria-label='greater or less than']")

     

    P.S. Hope, my statements are correct as per this: https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ms256086(v=vs.100)

     

    • tvklovesu's avatar
      tvklovesu
      Frequent Contributor

      Ha, that's a simple fix took me whole day to figure out. Why I forgot that ./ I don't know. But this fixed my issue. 

      Thanks so much