The problem that I am facing is that I can't seem to select that div class using XPath.
<div class="_3WZoe"><span dir="auto" class="">We can not found, try again.</span></div>
How can i do XPath, i don't know.
Thank You.
//div[contains(#class,"_3WZoe")]
Related
How to get exract xpath for the following name(I1888 - Child 1.1). now i am using following xpath "//span[contains(#class,'TreeTitleRed')][contains(.,'Child 1.1')]" but i need to get xpath without contains. please help me
<div>
<span> class ="Vegan tree"
<span class="treeTitlered">I1888 -Child 1.1</span>
</span>
</div>
You can use the following if you want it in xpath
//span[#class='treeTitlered']
Or you can directly find the locator by using the classname
driver.findElement(By.className(“treeTitlered”));
Hope this helps.
You can also use.
//div/child::span[1]/child::span[1]
This will surely work for you, do let me know in case of any further queries.
You can also use
//div/span/child::span[#class="treeTitlered"]
You can stick to parent <span> tag and locate it using its class attribute of Vegan tree.
Once done you can query its innerText property which will return I1888 - Child 1.1 text
Example code (assumes WebDriverWait just in case)
WebElement veganTree = new WebDriverWait(driver, 10)
.until(ExpectedConditions
.presenceOfElementLocated(By
.xpath("//span[#class='Vegan tree']")));
System.out.println(veganTree.getAttribute("innerText"));
Demo:
Could somebody help to understand what is wrong with element searching via Selenide.
I have such HTML code:
<div>
Current method:
<strong>
SMS
</strong>
</div>
The Selenium finds the element throw this xpath
findElement(By.xpath("//div[contains(. , \"Current method\")]/strong"))
but Selenide returns ElementNotFound exception with the same locator
$(By.xpath("//div[contains(. , \"Current method\")]/strong"))
If you need strong, you can just
$(By.xpath("//strong[contains(text(),'SMS')]"))
You can us following option.
$("strong:contains('SMS')"); Using css selectors method
You can try :
$(byText("Current method:")).shouldBe(Condition.exist);
Using Selenium->
findElement(By.xpath("//div[contains(text(), 'Current method')]/strong"));
Using Selenide->
$(By.xpath("//div[contains(text(), 'Current method')]/strong"));
These two method can be used in selenium as well as selenide.Methods are not specific to Selenium or selenide
When recorded in Selenium IDE, the result is this:
click
//span[#id='some_text']/table/tbody/tr/td/table/tbody/tr[2]/th/hd/font/span/acronym
Here is my entry in Eclipse using WebDriver(Java)
driver.findElement(By.xpath("//span[#id='some_text']/table/tbody/tr/td/table/tbody/tr[2]/th/h2/font/span/acronym")).click();
Here is the error I receive:
no such element: Unable to locate element:
{"method":"xpath","selector":"//span[#id='some_text']/table/tbody/tr/td/table/tbody/tr[2]/th/h2/font/span/acronym"},
HTML
<span onclick="change_site"('SITES');" style="cursor:pointer; color:#12345; text-decoration:underline;">
<acronym title=Site ID:">DEFAULTSITE</acronym>
</span>
As per the HTML provided you can directly access the acronym element
driver.findElement(By.xpath("//span/acronym[#title='Site Id:']")).click();
Try with below xPath :
driver.findElement(By.xpath("//acronym[contains(text(),'DEFAULTSITE')]").click();
Try any of the below xpath
driver.findElement(By.xpath("//acronym[text()='DEFAULTSITE']");
driver.findElement(By.xpath("//span/acronym[text()='DEFAULTSITE']");
Or this css
driver.findElement(By.css("acronym[title='Site']");
If none of the above Xpath has worked for you ,please try the following Xpath
//span[#id='some_text']/table/tbody/tr/td/table/tbody/tr[2]/th/hd/font/span/*[name()=acronym]
Please let me know if this has helped you or not.
How to choose cssSelector() from Chrome browser using Chrome Developer Tools?
Can you show an example for the below code?
WebElement searchBox = driver.findElement(By.cssSelector("selector"));
searchBox.click();
How to chose the value for the SELECTOR field from the Chrome Developer Tool?-F12 in Chrome. Please explain with an example
Thanks
If you are referring to Selenium like your tags imply, I guess you're trying to use
driver.findElements(By.className(".."));
or something similar, you need to be familiar with CSS Selectors.
for example if we inspect the stackoverflow logo we will see:
<div id="hlogo">
<a href="/">
Stack Overflow
</a>
</div>
So in this case we will use:
driver.findElements(By.id("hlogo"));
Or we can use a cssSelector by doing:
driver.findElements(By.cssSelector("#hlogo"));
If i understand you question properly, thats what you need:
$$("your_selector")
For example:
$$("#id_of_element")
$$("[type="text"]")
I have been working on java project which needs the selenium testing tool for running the test class. As per the requirement, I need to know how to write the xpath, and how to get the value (goodluck) using xpath for given tag.
<span class="clienthome" id="personTableForm:foundClientsTable:0:j_id118">
goodluck</span>
Please anyone kindly help me.
try - //span[#class='clienthome']/.[normalize-space(text())='goodluck']
or
//span[normalize-space(text())='goodluck']