我正在自动化基于angularJS的应用程序。我有一些复选框,它们具有相同的相对xpath
和相同的CSSselector
路径。绝对xpath
根本不起作用。
我试过了。如何处理?
.//* [@ ID =' subjectId'] / DIV [1] /标签
答案 0 :(得分:1)
如果在您的情况下elements
返回多个(.//*[@id='subjectId']/div[1]/label)[1]
,那么您需要使用索引来确定单个元素,如下所示: -
cssSelector
对于:nth-child(n)
,您需要使用 gameInfoMainViewController = UIStoryboard(name: "GameInfo", bundle: nil).instantiateViewControllerWithIdentifier("GameInfoMainViewController") as? GameInfoMainViewController
gameInfoMembersViewController = UIStoryboard(name: "GameInfo", bundle: nil).instantiateViewControllerWithIdentifier("GameInfoMembersViewController") as? GameInfoMembersViewController
gameInfoTeamsViewController = UIStoryboard(name: "GameInfo", bundle: nil).instantiateViewControllerWithIdentifier("GameInfoTeamsViewController") as? GameInfoTeamsViewController
gameInfoTeamsViewController!.delegate = self
// to be called in view didAppear
activeViewController = gameInfoMainViewController
private var activeViewController: UIViewController? {
didSet {
removeInactiveViewController(oldValue)
updateActiveViewController()
}
}
private func removeInactiveViewController(inactiveViewController: UIViewController?) {
if let inActiveVC = inactiveViewController {
inActiveVC.willMoveToParentViewController(nil)
inActiveVC.view.removeFromSuperview()
inActiveVC.removeFromParentViewController()
}
}
private func updateActiveViewController() {
if let activeVC = activeViewController {
addChildViewController(activeVC)
activeVC.automaticallyAdjustsScrollViewInsets = true
activeVC.view.autoresizingMask = [ UIViewAutoresizing.FlexibleHeight , UIViewAutoresizing.FlexibleWidth]
activeVC.view.frame = contentView.bounds
contentView.addSubview(activeVC.view)
// contentView is the containerView
activeVC.didMoveToParentViewController(self)
}
}
进行索引..
注意: - 如果您想要更好的解决方案,还需要共享您的HTML。
希望它会对你有所帮助.. :)
答案 1 :(得分:0)
我更改了x路径并添加了" @for =' Asses_21']"在HTML的相对x路径中,如在HTML中,所有重复的x路径都有不同的" Asses" 现在它看起来像这样。
".//*[@id='subjectId']/div[1]/label[@for='Asses_21']"
现在正在工作