单值上下文中的多值selection.Text()

时间:2018-05-22 08:24:40

标签: go

我在编译时遇到错误

单值上下文中的多值selection.Text()

var selection *agouti.Selection
s1 := a.page.FirstByXPath(`//*[@id="name"]`)
selection = s1
tmp_address = selection.Text() // Error is occurring at this Line.

请帮助解决此问题。

1 个答案:

答案 0 :(得分:1)

*agouti.Selection方法Text()返回(string, error)。请参阅源代码:https://github.com/sclevine/agouti/blob/dab7b01f206e43278618a7e0f5bc3ea39e48445a/selection_properties.go#L10

你需要这样做:

selection, err = s1 tmp_address = selection.Text() 

如果您想处理错误,或

selection, _ = s1 tmp_address = selection.Text() 

如果你想忽略它。

此外,如果您将来正确格式化问题,将有助于获得更好的回复。