How to Get Label Name from Button

How to get label name from Button?

If you are sure that titleLabel is not nil:

println(TheButton.titleLabel!.text)

else

if let text = TheButton.titleLabel?.text {
println(text)
}

How to get all the StoreName with button label Make My Store using xpath

This xpath should match all elements with text "Make My Store":

'//*[text() = "Make My Store"]'

Since you mention they are buttons, you could specify all buttons with text "Make My Store" as follows:

'//button[contains(text(), "Make My Store")]'

Oh, I see what you want now. To get the store name text above each button with "Make My Store", this xpath should work:

'//button[contains(text(), "Make My Store")]/parent//div[@class="StoreName"]'

You should be able to find the storename by getting the text of the element(s) found by the above xpath. I don't know what coding language you want to use otherwise I could give an example.

Get the text from label of Radiobutton

The problem is that you're trying to get innerText from the <input>, which has none. You need to get the <label>'s text:

for (var i=0; i<type.length; i++){
if(type[i].checked){
var title_type=type[i].nextElementSibling.innerText
console.log(title_type)
}
}

Changing Button Label and Title dynamically for Buttons created from Array (in swift)

There are a couple of issues going on here. The first is that in SwiftUI, generally you want your model to be a struct, since SwiftUI Views respond well to changes in value types (like a struct) out-of-the-box.

public struct Student {
public var first: String
public var last: String
public var state: Int
public var color: Color
public init(first: String, last: String, color: Color){
self.first = first
self.last = last
state = Int()
self.color = color
}
}

var john = Student(first: "John", last: "Lennon", color: .green)
var paul = Student(first: "Paul", last: "McCartney", color: .green)
var georg = Student(first: "Georg", last: "Harrison", color: .green)
var ringo = Student(first: "Ringo", last: "Starr", color: .green)

Note that I've also changed your code a bit to use the Swift conventions of capitalizing type names and lowercasing variable names.

Next, since you're trying to change properties on the Students, you'll want to represent them with a @State array. Then, by using the new element binding syntax on the ForEach line (see the $ characters), you can get a reference to each Student that you can modify.

struct ContentView: View {

@State private var students = [john, paul, georg, ringo]

let columnLayout = Array(repeating: GridItem(), count: 7)

var body: some View {
NavigationView{
ScrollView{
LazyVGrid(columns: columnLayout){
ForEach($students, id: \.last) { $student in

Button{
student.state += 1

if (student.state < 4) {
student.color = .green
}

else if (student.state >= 7){
student.color = .red
}

else {
student.color = .yellow
}

} label:{
ZStack{
RoundedRectangle(cornerRadius: 10, style: .continuous)
.foregroundColor(student.color)
.aspectRatio(2.0, contentMode: .fit)

Text("\(student.first) - \(student.state)")
.foregroundColor(.black)
.scaledToFit()
}
}
}
}
}.navigationTitle("Classroom Management")
}.navigationViewStyle(.stack)
}
}

Find html label associated with a given input

First, scan the page for labels, and assign a reference to the label from the actual form element:

var labels = document.getElementsByTagName('LABEL');
for (var i = 0; i < labels.length; i++) {
if (labels[i].htmlFor != '') {
var elem = document.getElementById(labels[i].htmlFor);
if (elem)
elem.label = labels[i];
}
}

Then, you can simply go:

document.getElementById('MyFormElem').label.innerHTML = 'Look ma this works!';

No need for a lookup array :)

How to get WebElement Button by label

You can use something like

// For the first case
driver.findElement(By.xpath("//td[text()='Some Text1']/preceding-sibling::td/input[@type='checkbox']")).click();

// For the second case
driver.findElement(By.xpath("//label[text()='Some Text2']/preceding-sibling::input[@type='radio']")).click();


Related Topics



Leave a reply



Submit