XPath contains(text(),’some string’) doesn’t work when used with node with more than one Text subnode

The <Comment> tag contains two text nodes and two <br> nodes as children. Your xpath expression was //*[contains(text(),’ABC’)] To break this down, * is a selector that matches any element (i.e. tag) — it returns a node-set. The [] are a conditional that operates on each individual node in that node set. It matches if … Read more

How to click on SVG elements using XPath and Selenium WebDriver through Java

Try following XPath and let me know if problem still persist: //div[@id=”avg_score_chart”]//*[name()=”svg”] For <g> elements: //div[@id=”avg_score_chart”]//*[name()=”svg”]/*[name()=”g”] Update Finally, this should be nearly the best option: //div[@class=”portlet light boxshadow”][contains(.,”Store Wise Performance”)]/div//div[@class=”amcharts-chart-div”]/*[name()=”svg”]//*[name()=”g”]/*[name()=”path” and @fill=”rgb(242,244,28)”]

Select iframe using Python + Selenium

This worked for me with Python (v. 2.7), webdriver & Selenium when testing with iframes and trying to insert data within an iframe: self.driver = webdriver.Firefox() ## Give time for iframe to load ## time.sleep(3) ## You have to switch to the iframe like so: ## driver.switch_to.frame(driver.find_element_by_tag_name(“iframe”)) ## Insert text via xpath ## elem = … Read more

Using Xpath With Default Namespace in C#

First – you don’t need a navigator; SelectNodes / SelectSingleNode should suffice. You may, however, need a namespace-manager – for example: XmlElement el = …; //TODO XmlNamespaceManager nsmgr = new XmlNamespaceManager( el.OwnerDocument.NameTable); nsmgr.AddNamespace(“x”, el.OwnerDocument.DocumentElement.NamespaceURI); var nodes = el.SelectNodes(@”/x:outerelement/x:innerelement”, nsmgr);

SimpleXML: Selecting Elements Which Have A Certain Attribute Value

Try this XPath: /object/data[@type=”me”] Which reads as: Select (/) children of the current element called object Select (/) their children called data Filter ([…]) that list to elements where … the attribute type (the @ means “attribute”) has the text value me So: $myDataObjects = $simplexml->xpath(‘/object/data[@type=”me”]’); If object is not the root of your document, … Read more

How can I match on an attribute that contains a certain string?

Here’s an example that finds div elements whose className contains atag: //div[contains(@class, ‘atag’)] Here’s an example that finds div elements whose className contains atag and btag: //div[contains(@class, ‘atag’) and contains(@class ,’btag’)] However, it will also find partial matches like class=”catag bobtag”. If you don’t want partial matches, see bobince’s answer below.

How to parse XML in Bash?

This is really just an explaination of Yuzem’s answer, but I didn’t feel like this much editing should be done to someone else, and comments don’t allow formatting, so… rdom () { local IFS=\> ; read -d \< E C ;} Let’s call that “read_dom” instead of “rdom”, space it out a bit and use … Read more

Testing text() nodes vs string values in XPath

XPath text() = is different than XPath . = (Matching text nodes is different than matching string values) The following XPaths are not the same… //span[text() = ‘Office Hours’] Says: Select the span elements that have an immediate child text node equal to ‘Office Hours`. //span[. = ‘Office Hours’] Says: Select the span elements whose … Read more

How to retrieve the text of a WebElement using Selenium – Python

The desired element is a dynamic element so to extract the text within the element you have to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following solutions: Using CSS_SELECTOR: print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, “p.value.noWrap[data-bind$=’MarketValue’]”))).get_attribute(“innerHTML”)) Using XPATH: print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, “//p[@class=”value noWrap” and contains(@data-bind,’MarketValue’)]”))).get_attribute(“innerHTML”)) Note : You have to add the following imports : … Read more