2016-03-01 105 views
0

在我的應用程序中,我需要點擊一個子元素,由於某種原因,它不工作。點擊appium中的一個子元素

這是父元素:

WebElement element = device.getDriverWrapper().getIosDriver().findElement(By.xpath("//UIACollectionView[1]/UIACollectionCell[4]")); 

該元素包含的TextView和鎖定。我需要按下鎖。

這是子元素:

WebElement child = element.findElement(By.xpath("//UIAButton[1]")); 
child.click(); 

任何想法,我做錯了什麼?

感謝

+0

你需要父元素嗎?是否有一個原因,你不只是使用「//UIACollectionView [1]/UIACollectionCell [4]/UIAButton [1]」? – econoMichael

回答

0

this,我建議修改爲:

WebElement child = element.findElement(By.xpath("/UIAButton[1]")); 

應該有所幫助。

0

將子元素的xpath從"//UIAButton[1]"更改爲".//UIAButton[1]"

xpath以"."開頭表示在父項下查找元素。如果不是,則意味着在根目錄下查找元素。