Selenium Following-Sibling - selenium

I am trying to find the xpath of an input field using following-sibling but not getting the correct xpath. Kindly suggest
http://admin-demo.nopcommerce.com/
(userid = admin#yourstore.com || Password = admin)
Click on catalog > Categories > Add New
Here - I am trying to find the xpath of the select field opposite to Limited to customer roles and my xpath is //label[text()='Limited to customer roles']/following-sibling::div but it is not working. Also, I tried xpath = //div[#class='k-multiselect-wrap k-floatwrap'] but it is displaying 3 comman xpaths but my requirement is to find the select field opposite to Limited to customer roles only.

"//label[text()='Limited to customer roles']//ancestor::div[#class='col-md-3']/following-sibling::div//div[#class='col-md-4']/div"
Click on this div displays the dropdown.

Related

how to select textView without id in appium?

I'm new to automation and appium
so I'm trying to automate sololearn
I have such a list of relativeLayouts each one contains a follower picture, name, and lvl. here is an image for more details
https://drive.google.com/file/d/1VIeK3tPmzv_crEX0DQ68UH9a3cUTKNlD/view?usp=sharing
I was able to select those relativeLayouts in a list by doing this
followersList = driver.find_elements_by_id("com.sololearn:id/facebook_friends_view_layout")
which gives me this list:
[<appium.webdriver.webelement.WebElement (session="33b98510-b0e1-45bd-af6c-9ca830e938fe", element="92ebaa8f-321e-4897-9f5b-df6cc38afc8e")> , <appium.webdriver.webelement.WebElement (session="33b98510-b0e1-45bd-af6c-9ca830e938fe", element="d21e273f-db0c-4d4d-8937-dbc52b437c99")>]
Can I now extract the textView that contains the names of followers from that list?
idk I lack knowladge but I'm comparing it to js and html where you can get first children of elements and things like that. Can i do that here? is there any other possible ways?
I don't want to use xpaths , and the name elements doesn't have and id so I can't select it with it's id.
my goal is to get all followers names in a table.
Help please, and thanks <3
Got it
this is my solution
followersList = driver.find_elements_by_id("com.sololearn:id/facebook_friends_view_layout")
for follower in followersList:
followerName = follower.find_element_by_id("com.sololearn:id/user_name")
print(followerName.text)

Need to locate XPath of email address

Its generated dynamically based on user login, Also the class="row-left" is used for 3 elements on the same page and XPath //div[text()='~~' and #class = 'row-left'] is not locating the element.
You can find the required div element using child element as below and It will point the highlighted div.
//label[text()='Email Address']/parent::*
If you want to get the value of the dynamic email, you can get it as below
driver.findElement(By.xpath("//label[text()='Email Address']/parent::*")).getText();
It will give the dynamic email ID

How to click an element with reference to another web element in Selenium WebDriver(Java)?

There are many span tags as mentioned in the image below and each has its own a-tag with unique id as "chooseitem". I need to choose particular a tag using names in the span tags.
Need to click the a-tag button using the text Mayo Chicken from the above HTML snippet in the image.
I have tried the below Selenium script
WebElement select = driver.findElement(By.xpath("//*[contains(text(),'Mayo Chicken (Single)')]"));
WebElement add = select.findElement(By.id("chooseitem"));
It doesn't work for me.
driver.findElement(By.id("chooseitem"));
The above code chooses the first item in the page by default as its id is also 'chooseitem', but need to define what to be chosen.
Can anybody help me out?
We need to get the common parent(ancestor) element of the chicked and the clickable 'a' tag, then we can navigate to the tag 'a'. Below xpath should ideally work.
"//span[contains(text(),'Mayo chicken')]/ancestor::div[4]//a"
Note: Here i have used div[4] because fourth parent is the common ancestor for 'Mayo chicken' and tag 'a'.
For more details about different xpath axis refer this->https://www.w3schools.com/xml/xpath_axes.asp
Hope this helps you. thanks.
You can do that by using the xpath position, press F12 for developer tools click on "Select element button", click the element that interests you on the page, as in your picture you will see one or more lines highlighted, right click the line -> Copy -> Copy xpath. You will have something like the line below:
//*[#id="comment-76500216"]/td[2]/div/span[1]
The xpath position will be:
//td[2]/div/span[1]
You can use that when you have multiple elements that share the name or id or so on.
And you will have:
WebElement select = driver.findElement(By.xpath("//td[2]/div/span[1]"));
PS: I used google chrome

How to locate 5 different choose file option having same xpath in selenium webdriver?

enter image description here
I created my own xpath using the value as
.//*[#onclick='return clickFileUpload('openssme1')']
But it is not locating the choose file option individually.
Please help me to locate them individually so that i can choose 5 files.
If I want to select a specific element and I know the position in the result generated by the xpath. Then you can simply append [n] to the end of the xpath, where n is the position number.
(//button[text()="Choose File"])[1]
You can select your element with other unique identifier. In your case, you can choose the number at the left of your button (the number)
Something like this :
//*[#id='uploaderList']/tr/td[contains(text(),'1')]/../td/button

how to select the check box using selenium?

How to select the checkbox which has a dynamically changing ID and XPath?
Multiple ways:
You should look at a pattern like id or name somoething like
CT_CHKBox_157, CT_CHK_158 etc.. For example, to click the first
Checkbox having a pattern of Ids
You can use a dynamic xpath like driver.findelement(By.xpath(//input[starts-with(#id,'CT_CHK'][1]).click()
Identify the Unique Element which are close ancestors to the
Checkbox in question and reach out to it through xpath or css path
relatively or through indexing from within.
Hope that clarifies.
Have you tried XPath by position? Ultimately the check boxes are like buttons or link that can be clicked so driver.findElement(By.xpath("//xpath by position")).click();
Alternativey you might want to use JavaScript:
((JavascriptExecutor) driver).executeScript("return document.getElementsByName('ChkboxValue')[0].checked;");
Hope this helps.
Selenium uses what is called locators to find and match the elements.There are 8 locators strategies included in Selenium:
Identifier
Id
Name
Link
DOM
XPath
CSS
UI-element
you can try using any other Locator in the list.