Element
#struct ElementA handle to one element of the running page, found by id or key, used by tests and by handlers to read and change it.
| Name | Type | Description |
|---|---|---|
id | str = "" | The id the handle looks for. |
key | str = "" | The key the handle looks for when no id is given. |
/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.ui
func report():
t := ui.ById("t")
k := ui.ByKey("agree")
go := ui.ById("go")
println "exists", t.Exists(), ui.ById("nope").Exists(), k.Exists()
println "tag", t.Tag(), k.Tag(), go.Tag()
println "text", go.Text()
go.SetText("Again")
println "text", go.Text()
println "value", t.Value()
t.SetValue("hello")
println "value", t.Value()
println "checked", k.Checked()
k.SetChecked(true)
println "checked", k.Checked()
println "attr", t.Attr("placeholder")
t.SetAttr("placeholder", "name")
println "attr", t.Attr("placeholder")
t.Focus()
println "event", ui.CurrentEvent().kind, ui.CurrentEvent().target
go.ScrollIntoView()
r := go.Rect()
println "rect", r.width > 0.0, r.height > 0.0
s := t.Style()
println "style", s.visible
t.Click()
end
func main:
ui.SetUrlOpener((url: str): ret url.Len() > 0 end)
ui.SetNavigator((url: str): ret url.Len() > 0 end)
ui.RunPage((): ret ui.NoPatches() end, (b: ui.Builder): b.Open("input") b.Id("t") b.Attr("type", "text") b.On("click", (): println "clicked t" end) b.Close() b.Open("checkbox") b.Key("agree") b.Close() b.Open("button") b.Id("go") b.On("click", (): report() end) b.Text("Go") b.Close() end)
println "open", ui.OpenUrl("https://example.com")
println "opened", ui.OpenedUrls().Len()
ui.RunSteps("quit")
ui.Stop()
end