I am trying to use a webapp clock vs. my system clock to trigger events. I want to scrape the value of the webapp clock (serverClock).
The source code for the page contains:
<p class="server_time">
<span class="serverTime">Today's date is: <b>Thursday 12/15/2022</b></span>
<span class="serverClock"><span>The Server Time is: <b class="jquery_server_clock" data-
ftclub="canyonoakscc"></b></span>
</p>
To print the value of the webapp clock (serverClock) you can use either of the following locator strategies:
Using css_selector:
print(driver.find_element_by_css_selector("p.server_time span.serverClock > span b").get_attribute("value"))
Using xpath:
print(driver.find_element_by_xpath("//p[#class='server_time']//span[#class='serverClock']/span//b").get_attribute("value"))
Note : You have to add the following imports :
from selenium.webdriver.common.by import By
Related
How can use whatsapp xpath or css(Chromedriver) in vb.net.
HTML:
<span data-testid="send" data-icon="send" class>...</span> ==$0
xpath:
//*[#id="main"]/footer/div[1]/div/span[2]/div/div[2]/div[2]/button/span
I tried but not working:
driver.FindElement(By.CssSelector("span[data-testid='send' data-icon='send']")).Click()
As per the HTML:
<span data-testid="send" data-icon="send" class>...</span>
To click on the element you can use either of the following Locator Strategies:
Using FindElementByCss:
Driver.FindElementByCss("span[data-testid='send'][data-icon='send']").Click()
Using FindElementByXPath:
Driver.FindElementByXPath("//span[#data-testid='send' and #data-icon='send']").Click()
References
You can find a couple of relevant detailed discussions in:
How to click on the element using Selenium and VB.Net
it should be like
driver.FindElement(By.CssSelector("span[data-testid='send'][data-icon='send']")).Click()
when select specific attributes :
span[data-testid='send']
to add attributes to same tag :
span[data-testid='send'][data-icon='send']
*no space between attributes
Need a resource not Selenium documentation or W3C website, all there is information about Java, Python codes. I need to see how to use FindElement(By) in VBA or
.FindElementByCss("li > div > a=[href]").Click
The most useful site with examples I found is https://endtest.io/guides/blog/2020/07/31/a-practical-guide-for-finding-elements-with-selenium/
You were close enough. As an example for the following HTML:
<li>
<div>
Stack Overflow
</div>
</li>
To identify the desired element you can use either of the following locator strategies:
Using FindElementByCss:
.FindElementByCss("li > div > a[href]")
Using FindElementByCss (canonically):
.FindElementByCss("li > div > a[href*='stackoverflow']")
Using FindElementByXPath (canonically):
.FindElementByXPath("//li/div/a[#href=\"https://stackoverflow.com\"]")
I am inspecting one button element from a web page using chrome driver and selenium. And the html code for the particular button is:
<div class="label text-left text-link link-blue text-
uppercase">Financial Statement Analysis <span class="count">(2)</span>
</div>
I have tried different element options like find element by name, xpath, link text etc. But none of them unable to locate the element.
What will be the element to locate the button. ?
try Xpath :
//span[contains(#class,'count') and text() = '(2)']
You can try with this css selector :
div.label.text-left.text-link.link-blue.text-.uppercase
To locate the element with text as Financial Statement Analysis (2) you can use the following solution:
Java Solution:
WebElement elem = driver.findElement(By.xpath("//div[#class='label text-left text-link link-blue text-uppercase'][contains(.,'Financial Statement Analysis')]"));
how to locate only parent span which is containing the price value from the below Code,locator strategy doesn't matter:
<div class="price-box price-margin">
<p class="old-price"></p>
<p class="special-price">
<span id="product-price-75254" class="price">
56,90 €
<span class="steuerstern">*</span>
</span>
</p>
</div>
The issue is not the selector here. But the text function.
//p[#class="special-price"]/span[#class="price"]
This will select the node, but selenium will always return the node of the child nodes also. What you are looking for is the node text in this case. This can only be done using JavaScript. Since you didn't mention a language I am going to assume python
elem = driver.find_element_by_xpath('//p[#class="special-price"]/span[#class="price"]')
price = driver.execute_script("return arguments[0].firstChild.textContent.trim();", elem)
print(price)
56,90 €
Using selector you can go like this:
".price-box span.price"
Result:
56,90 €
To test the xpath correctness in Chrome you can use
//span[#class="price"]/text()
Since you didn't mention the language you use , here is an example in nightwatchjs with selenium by using .getText()
.getText() is returning an object, the actual text is the value of callback.
var thetext='';
.getText('//span[#class="price"]' ,fucntion(result){
thetext=result.value();
})
As you haven't mentioned the Selenium bindings you are using so I will construct an Answer through Java bindings. Here we will use a customized xpath to locate the node with text 56,90 € with out the * as follows:
WebElement ele = driver.findElement(By.xpath("//p[#class='special-price']/span[contains(#class,'price') and not(#class='steuerstern')]"));
I am using Selenium IDE and need to store a span id value:
<span id="ustData"
data-itemId="2130078"></span> <div class="clear"></div>
</div>
I want to store the value "2130078". This value changes for each page but is not visible. I have looked far and wide for a solution.
Currently using xpath location:
StoreAtribute
//data-itemId[#span='ustData']
From documentation I have read this seems correct?
When I run the test I get: [error] Element //data-itemId[#span='ustData'] not found
Any help would very much appreciated.
Your XPath should be:
//span[#id='ustData']
to match your span tag with an id attribute of 'ustData'
Then if you want to get the data-itemId attribute you can do:
//span[#id='ustData']/#data-itemId