VBA selenium selecting an element with ext:qtip attribute - vba

I'm trying to select and element which has a specific atribute.
<div class="x-grid3-cell-inner x-grid3-col-7 x-unselectable" unselectable="on" ext:qtip="Final" style="background:none;with=100%;background-image:url(/images/18_status_final.png);background-repeat:no-repeat;background-position:center;" id="flgstatus_id"> </div>
It's : "ext:qtip='Final'.
I'm trying to select it with
bot.FindElementByXPath("//div[contains(.,'Final')]").Click
It returns: element not found.
However i am able to select it using
bot.FindElementByXPath("//div[2]/table/tbody/tr/td[8]/div").Click
My goal is to check if an element has 'Final' and select it.
Thank you for your help.

FindElementByCss("[ext\:qtip=Final]")
to select it
bot.FindElementsByCss("[ext\:qtip=Final]").Item(2).Click
to choose an item.

Related

Find Xpath to an element depending on the value of another element in a table row

I'm new to Xpath so if this doesn't contain all relevant information apologies & let me know what you need to solve it.
I am trying to find an Xpath to an "expand arrow" element which expands a row in a table. The "expand arrow" element isn't unique so I would like to select it based on text contained in another element on the same row. The layout is as follows:
<td id="__table2-rows-row10-col0">
<div class="sapUiTableCellFlex">
<span id="__table2-rows-row10- treeicon" title="Expand Node" role="button">
<div id="__hbox27-__clone101">
<div id="__data70-__clone101">
<div id="__data71-__clone101">
<span id="__text47-__clone101" title="sys-admin">sys-admin</span>
I'd like to select the element with title = "Expand Node"
<span id="__table2-rows-row10- treeicon" title="Expand Node" role="button">
based on the element with title or text = "sys-admin"
<span id="__text47-__clone101" title="sys-admin">sys-admin</span>
I've played around with various options but I can't seem to get it to work. Any ideas would be much appreciated!
Thanks
To locate the element with title as Expand Node with respect to the element with title or text as sys-admin you can use either of the following Locator Strategies:
xpath and title attribute:
"//span[#title='sys-admin']//ancestor::span[#title='Expand Node']"
xpath and text() attribute:
"//span[text()='sys-admin']//ancestor::span[#title='Expand Node']"
I eventually got it to work using the following xpath:
//span[#title='sys-admin']/../../preceding-sibling::span[#title='Expand Node']

Selenium preceding returns a pointer/address and full xpath return a different pointer/address to what I believe should be the same object

Relative Xpath
WebElement precedingClass = driver.findElement(By.xpath("//div[contains(#class, 'pictures')]/preceding::div[contains (#class 'monkey picture') ]"));
Absolute Xpath
WebElment fullXpathAddress = driver.findElement(By.xpath("/html/body/div[6]/div/div[1]/div[1]/div/div[2]/ul/li[20]/div[1]");
HTML Code:
<div class="pictures">
<a ref ....>
<a ref ....>
<h1>x's pictures</h1>
</div>
<div class="animals">
<div class="monkey picture" title="happy monkey"></div>
.
.
</div>
Preceding: Select all nodes that come before the current node.
And you want to select node that is after the current node.
Maybe you can use following as below :
"//div[contains(#class, 'pictures')]/following::div[#class='animals']/div[#class='monkey picture']"
please refer this link to learn more about Xpaths
Please optimize the above Xpath based on your whole DOM structure.
Your Xpath seems wrong
Try below Xpath:
//div[#class='pictures']/following-sibling::a//div[#class='monkey picture']
So the code will be like:
WebElment element = driver.findElement(By.xpath("//div[#class='pictures']/following-sibling::a//div[#class='monkey picture']");
I was able to use preceding::div[x] since I was able to determine index of div "monkey picture" in the list of animals and from the start of animals, the number of divs preceding to "pictures was a fixed value.

How to write the XPath using sibling?

How to write the XPath using sibling?
I am trying to get the price value of the delivery fee using the sibling. But I am unable to get the XPath for the price tag below is the HTML code.
<div class="grid_3 d-grid_10">
<label class="m-confirmation-modal-print-detail-capgrey"> Delivery Fee:</label>
</div>
<div class="grid_1 d-grid_2">
<label class="m-confirmation-modal-print-price text-align-right"> $9.00</label>
</div>
You can try this:
//div[contains(., ' Delivery Fee:')]/following-sibling::div/label
Explanation to xPath: //div[contains(., ' Delivery Fee:')] finds a div on the top, then /following-sibling::div will select all next siblings div below our div. In our case only the next div. And finaly /label locates the element with value $9.00.
More information here
You can try this :
//label[contains(text(),' Delivery Fee:')]/parent:div/following-sibling::div/label
But yes #Andrei solution make much sense to use.

not able to select the dependent dropdown value in selenium

system is giving me unable to locate element error message
scenario is i have to select the occupation list which contains values like salaried, self employed(Business) , Self employed(Professional)etc.. on the basis of which the value values will be populated in next dropdown list i am using below code.
driver.findElement(By.id("select2-ED_EmpType-container")).click();
Thread.sleep(4000);
driver.findElement(By.xpath("//*[text()='Salaried']")).click();
the above code is working for other dropdowns bt not working for this dropdown
properties of this dropdown
<ul id="select2-ED_EmpType-results" class="select2-results__options" role="tree" aria-expanded="true" aria-hidden="false">
<li class="select2-results__option" role="treeitem" aria-selected="false"> Please select... </li>
<li id="select2-ED_EmpType-result-nhlf-Salaried" class="select2-results__option" role="treeitem" aria-selected="true"> Salaried </li>
It seems there is space in your string use below xpath
//li[normalize-space() ='Salaried']
To click on the option item Salaried you can use either of the following line of code :
cssSelector :
driver.findElement(By.cssSelector("li.select2-results__option#select2-ED_EmpType-result-nhlf-Salaried")).click();
xpath :
driver.findElement(By.xpath("//li[class='select2-results__option' and id='select2-ED_EmpType-result-nhlf-Salaried']")).click();

Selenium WebDriver : Not able find xpath for Paytm.com , Proceed button

I was trying to automate paytm.com site ,
Here i found Proceed button attribute has name but when i tried to use xpath checker for the name attribute , it was showing 13 matches but my question here is in the webpage from the UI level am not able to see 13 Proceed buttons instead only one Proceed button are present .
Even i tried with other attribute to find the xpath , but it showing more matches found.
Below is the HTML code for Proceed
<div class="msg-container">
<div class="btn-spinner" alt="Proceed to Recharge">
<div class="spinner hidden"></div>
<input class="btn proceed active" type="submit" data-express-text="Recharge Now" data-soft-block-text="Proceed anyway" data-default-text="Proceed" name="Proceed" value="Proceed" alt="Proceed to Recharge">
Can you please let me where am going wrong ?
This xpath returns 1 match for me
//form[#id='prepaidMobile']//input[#name='Proceed']
Also, if want use only //input[#name='Proceed'] you can get it from List of WebElements:
WebElement firstInput = driver.findElements(by.xpath("//input[#name='Proceed']"))[0];
This will work for you, I think:
driver.findElement(By.xpath("(//input[#name='Proceed'])[1]")));