如何为父元素编写CSS选择器

时间:2017-11-28 10:00:44

标签: selenium css-selectors

我已经尝试了card-paragraph-textbox.blue-highlight :parent .edit-Text ,但它无效:

例如:

card-paragraph-textbox.blue-highlight

孩子的班级名称: .edit-Text

父级的班级名称: :parent

关键字: let session = URLSession.shared var request = URLRequest(url: URL(string:"https://api.mailgun.net/v3/sandboxXXX.mailgun.org/logs")!) request.httpMethod = "POST" let key = "api:key-XXX" request.setValue("Basic \(toBase64(string: key))", forHTTPHeaderField: "Authorization") let task = session.dataTask(with: request, completionHandler:{(data, response, error) in if let err = error { print(err) } if let response = response { print("url = \(response.url!)") print("response = \(response)") let httpResponse = response as! HTTPURLResponse print("response code = \(httpResponse.statusCode)") } }) task.resume()

请帮忙!!

1 个答案:

答案 0 :(得分:1)

没有办法,请改用XPath。

获取父母:

//*[@class='edit-Text']

通过孩子获得父母:

//*[@class='card-paragraph-textbox blue-highlight']/..

//*[@class='card-paragraph-textbox blue-highlight']/parent::*