我正在使用以下版本:
我的脚本打印属于相关findelement
的{{1}}个值的路径。不确定element
中定义的路径是findelement
的根本原因还是新版本。ChromeDriver
。运行测试脚本后,我会在控制台中关注:
[[ChromeDriver: chrome on XP (8d6e0228a90daac67d21f6c2ff1c0ef3)] -> xpath: html/body/max-app-root/max-explore/div[2]/div[1]/p]
[[ChromeDriver: chrome on XP (8d6e0228a90daac67d21f6c2ff1c0ef3)] -> class name: ng-star-inserted]
[[ChromeDriver: chrome on XP (8d6e0228a90daac67d21f6c2ff1c0ef3)] -> class name: card-price]
[[ChromeDriver: chrome on XP (8d6e0228a90daac67d21f6c2ff1c0ef3)] -> class name: card-subtitle]
[[ChromeDriver: chrome on XP (8d6e0228a90daac67d21f6c2ff1c0ef3)] -> class name: explore-mi]
[[ChromeDriver: chrome on XP (8d6e0228a90daac67d21f6c2ff1c0ef3)] -> xpath: html/body/max-app-root/max-explore/max-campaign-information/div/aside/div[1]/div[1]/h4]
[[ChromeDriver: chrome on XP (8d6e0228a90daac67d21f6c2ff1c0ef3)] -> xpath: html/body/max-app-root/max-explore/max-campaign-information/div/aside/div[1]/div[2]/h4]
[[ChromeDriver: chrome on XP (8d6e0228a90daac67d21f6c2ff1c0ef3)] -> xpath: html/body/max-app-root/max-explore/max-campaign-information/div/aside/div[2]/div[1]/div[1]/div/div[1]/p]
[[ChromeDriver: chrome on XP (8d6e0228a90daac67d21f6c2ff1c0ef3)] -> xpath: html/body/max-app-root/max-explore/max-campaign-information/div/aside/div[2]/div[1]/div[1]/div/div[2]/p]
[[ChromeDriver: chrome on XP (8d6e0228a90daac67d21f6c2ff1c0ef3)] -> xpath: html/body/max-app-root/max-explore/max-campaign-information/div/aside/div[2]/div[1]/div[2]/p]
[[ChromeDriver: chrome on XP (8d6e0228a90daac67d21f6c2ff1c0ef3)] -> xpath: html/body/max-app-root/max-explore/max-campaign-information/div/aside/div[2]/div[2]/div/div[1]/div/p]
[[ChromeDriver: chrome on XP (8d6e0228a90daac67d21f6c2ff1c0ef3)] -> xpath: html/body/max-app-root/max-explore/max-campaign-information/div/aside/div[2]/div[2]/div/div[2]/div/p]
[[ChromeDriver: chrome on XP (8d6e0228a90daac67d21f6c2ff1c0ef3)] -> xpath: html/body/max-app-root/max-explore/max-campaign-information/div/aside/div[2]/div[3]/div/div[1]/div[1]/h4]
[[ChromeDriver: chrome on XP (8d6e0228a90daac67d21f6c2ff1c0ef3)] -> xpath: html/body/max-app-root/max-explore/max-campaign-information/div/aside/div[2]/div[3]/div/div[1]/div[2]/p]
我的脚本如下所述:
`
@Test(priority = 13)
public void Explore_check_input_in_feedback () throws InterruptedException
{
WebElement CampaignName = driver.findElement(By.xpath("html/body/max-app-root/max-explore/max-campaign-information/div/aside/div[1]/div[1]/h4"));
WebElement NowPay = driver.findElement(By.xpath("html/body/max-app-root/max-explore/max-campaign-information/div/aside/div[1]/div[2]/h4"));
WebElement StartDate = driver.findElement(By.xpath("html/body/max-app-root/max-explore/max-campaign-information/div/aside/div[2]/div[1]/div[1]/div/div[1]/p"));
WebElement EndDate = driver.findElement(By.xpath("html/body/max-app-root/max-explore/max-campaign-information/div/aside/div[2]/div[1]/div[1]/div/div[2]/p"));
WebElement Estimations = driver.findElement(By.xpath("html/body/max-app-root/max-explore/max-campaign-information/div/aside/div[2]/div[1]/div[2]/p"));
WebElement Budget = driver.findElement(By.xpath("html/body/max-app-root/max-explore/max-campaign-information/div/aside/div[2]/div[2]/div/div[1]/div/p"));
WebElement BusinessOutcome = driver.findElement(By.xpath("html/body/max-app-root/max-explore/max-campaign-information/div/aside/div[2]/div[2]/div/div[2]/div/p"));
WebElement TotalCost = driver.findElement(By.xpath("html/body/max-app-root/max-explore/max-campaign-information/div/aside/div[2]/div[3]/div/div[1]/div[1]/h4")) WebElement Savings = driver.findElement(By.xpath("html/body/max-app-root/max-explore/max-campaign-information/div/aside/div[2]/div[3]/div/div[1]/div[2]/p"));
CampaignName.getSize();
Assert.assertTrue(CampaignName != null);
System.out.println(CampaignName);
NowPay.getSize();
Assert.assertTrue(NowPay != null);
System.out.println(NowPay);
StartDate.getSize();
Assert.assertTrue(StartDate != null);
System.out.println(StartDate);
EndDate.getSize();
Assert.assertTrue(EndDate != null);
System.out.println(EndDate);
Estimations.getSize();
Assert.assertTrue(Estimations != null);
System.out.println(Estimations);
Budget.getSize();
Assert.assertTrue(Budget != null);
System.out.println(Budget);
BusinessOutcome.getSize();
Assert.assertTrue(BusinessOutcome != null);
System.out.println(BusinessOutcome);
TotalCost.getSize();
Assert.assertTrue(TotalCost != null);
System.out.println(TotalCost);
Savings.getSize();
Assert.assertTrue(Savings != null);
System.out.println(Savings);
}`
答案 0 :(得分:0)
由于我更新了ChromeDriver
,因此要进行打印,我必须明确定义它。
例;如果在脚本中定义了WebElement Error
并且我写了System.out.println(Error)
,它将打印元素的path
。我必须提到System.out.println(Error).getText()
而不是打印实际值。