簡體   English   中英

將Web元素的大小轉換為整數變量時面臨的問題

[英]facing issue while getting size of web element into a integer variable

類型不匹配:無法從尺寸轉換為整數。

int sizeOfServiceInstanceRow = driver.findElement(By.xpath("//table/tbody/tr[4]/td/table/tbody/tr")).getSize();

我們應該在sizeOfServiceInstanceRow變量中確定Web元素的大小。

從selenium docs中, getSize返回一個Dimension對象(其中包含height和width屬性),您不能直接將其int轉換為int類型。

如果您對獲取元素的高度和寬度感興趣,則可以執行以下操作。

Dimension elemDimension = driver.findElement(By.xpath("//table/tbody/tr[4]/td/table/tbody/tr")).getSize();
int height  = elemDimension.getHeight();
int width   = elemDimension.getWidth();

請參閱docs https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebElement.html#getSize--

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM