Posts

Showing posts with the label Xpath

Access #text Property Of XMLAttribute In Powershell

Answer : Besides #text , you can also access XmlAttribute 's value via Value property : $attr = $xml.SelectSingleNode("//obj/indexlist/index[@name='DATE']/@value") #print old value $attr.Value #update attribute value $attr.Value = "new value" #print new value $attr.Value Note that Value in $attr.Value is property name of XmlAttribute . It doesn't affected by the fact that the attribute in your XML named value . Don't select the attribute, select the node. The attributes of the node will be represented as properties and can be modified as such: $node = $xml.SelectSingleNode("//obj/indexlist/index[@name='DATE']") $node.value = 'foo' Use a loop if you need to modify several nodes: $nodes = $xml.SelectNodes("//obj/indexlist/index[@name='DATE']") foreach ($node in $nodes) { $node.value = 'foo' }

Click Button By Text Using Python And Selenium

Answer : You can find all buttons by text and then execute click() method for each button in a for loop. Using this SO answer it would be something like this: buttons = driver.find_elements_by_xpath("//*[contains(text(), 'My Button')]") for btn in buttons: btn.click() I also recommend you take a look at Splinter which is a nice wrapper for Selenium. Splinter is an abstraction layer on top of existing browser automation tools such as Selenium, PhantomJS and zope.testbrowser. It has a high-level API that makes it easy to write automated tests of web applications. I had the following in html: driver.find_element_by_xpath('//button[contains(text(), "HELLO")]').click()