ВШ
Size: a a a
ВШ
А
V
ВШ
А
AM
V
AM
MK
А
СС
DM
SD
А
AM
AM
R(
ДИ
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
A
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
ДИ
public class Product implements IProduct {
private String id;
private String linkSelector;
private String priceSelector;
WebDriver driver;
Wait<WebDriver> waiter;
public Product(String id, WebDriver driver) {
this.waiter = new WebDriverWait(driver, 50).ignoring(StaleElementReferenceException.class, ElementNotVisibleException.class);
this.id = id;
////*[contains(@id,'product-518204228')]/*[contains(@class,'n-snippet-card2__part_type_center')]//*[contains(@class,'n-snippet-card2__title')]/a
this.linkSelector = String.format(
"//*[contains(@id,'%s')]" +
"/*[contains(@class,'n-snippet-card2__part_type_center')]" +
"//*[contains(@class,'n-snippet-card2__title')]/a", id);
this.priceSelector = String.format("//*[contains(@id,'%s')]/*[contains(@class,'n-snippet-card2__part_type_right')]//div[@class='price']", id);
this.driver = driver;
}
public String getId() {
return this.id;
}
public String getName() {
// WebElement element = waiter.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath(linkSelector))));WebElement
WebElement element = driver.findElement(By.xpath(linkSelector));
return element.getText();
}
public Number getPrice() {
WebElement element = driver.findElement(By.xpath(priceSelector));
// WebElement element = waiter.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath(priceSelector))));
String value = element.getText();
String intVal = value.replaceAll("[^\\d]", "");
return Integer.parseInt(intVal);
}
}