【发布时间】:2018-01-02 19:42:44
【问题描述】:
我对 iframe 选项卡有疑问。我的网页在使用 3rd 方链接打开的单独选项卡中有一个 iframe。我想通过去每个标签来抓住它,但没有任何办法去做。
HTML 代码:
<ul class="resp-tabs-list">
<li class="resp-tab-item resp-tab-active" aria-controls="tab_item-0" role="tab">
<a class="js-tab-list js-tab-1" data-source="https://www.adsdssas.com/property/individual/BC-2030877?isl=1" data-no="1" data-ga="0" target="iframe_1">
<img src="/themes/centralization/images/partners-tab-logo/rentalhomes-tab-logo.png" alt="RentalHomes.com" height="20" width="auto">
</a>
</li>
<li class="resp-tab-item" aria-controls="tab_item-1" role="tab">
<a class="js-tab-list js-tab-1" data-source="https://www.jdoasdadadqocy.com/click-8111003-11553823?url=https%3A%2F%2Fwww.vrasbo.com%2Fvacation-rentals%3Fq%3DDauphin%2BIsland%252C%2BAL%252C%2BUSA&utm_campaign=RENTALHOMES&sid=MTUwMTE0MTI4NDIwMi41LjUwLjQzLTM&label=MTUwMTE0MTI4NDIwMi41LjUwLjQzLTM&ft=1" data-no="1" data-ga="0" target="iframe_1">
<img src="/themes/centralization/images/partners-tab-logo/feed_logo_vrbo.png" alt="VRBO.Com" height="20" width="auto">
</a>
</li>
<li class="resp-tab-item" aria-controls="tab_item-2" role="tab">
<a class="js-tab-list js-tab-1" data-source="https://www.jdadsdoqocy.com/click-8111003-10859031?url=https%3A%2F%2Fwww.homeaway.com%2Fresults%2Fkeywords%3ADauphin%2BIsland%252C%2BAL%252C%2BUSA&utm_campaign=RENTALHOMES&sid=MTUwMTE0MTI4NDIwMi41LjUwLjQzLTM&label=MTUwMTE0MTI4NDIwMi41LjUwLjQzLTM&ft=1" data-no="1" data-ga="0" target="iframe_1">
<img src="/themes/centralization/images/partners-tab-logo/feed_logo_12.png" alt="HomeAway.Com" height="20" width="auto">
</a>
</li>
<li class="resp-tab-item" aria-controls="tab_item-3" role="tab">
<a class="js-tab-list js-tab-1" data-source="https://www.dddoaoa.com/click-8111003-11327743?url=https://www.asdasd.com/search.do?q-destination=Dauphin+Island%2C+AL%2C+USA&utm_campaign=RENTALHOMES&sid=MTUwMTE0MTI4NDIwMi41LjUwLjQzLTM&label=MTUwMTE0MTI4NDIwMi41LjUwLjQzLTM&ft=1" data-no="1" data-ga="0" target="iframe_1">
<img src="/themes/centralization/images/partners-tab-logo/feed_logo_14.png" alt="Hotel.Com" height="20" width="auto">
</a>
</li>
</ul>
我们将不胜感激任何类型的帮助
Thanks @anshul
我运行你的代码,但它打印相同的 url 4 次。我想采用 iframe url 和
@Test
public void DetailsPageSliderTAB_For_BC() throws InterruptedException{
wd.manage().window().maximize();
wd.get("http://192.168.2.116/check/");
wd.findElement(By.xpath(".//*[@id='Rentalhomes']/div/div/div/table/tbody[4]/tr[6]/td[1]/a")).click();
wd.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
String HotelonBCP=wd.findElement(By.xpath(".//*[@class='air-bnb-checkbox checkbox']")).getText();
wd.findElement(By.xpath(".//*[@id='lightbox-pop']/div/div/div/div[2]/div/div[5]/div[2]/div[2]/div/a")).click();
wd.findElement(By.xpath(".//*[@id='start_now11']")).click();
Thread.sleep(200000);
Reporter.log("POP Under Name "+HotelonBCP);
for (String windows : wd.getWindowHandles()) {
wd.switchTo().window(windows);
if (wd.getCurrentUrl().startsWith("http://staging.rentalhomes.com")) {
List<WebElement> liElementList = wd.findElement(By.id("horizontalTabAffiliate")).findElement(By.xpath("//ul[contains(@class,'resp-tabs-list')]")).findElements(By.tagName("li"));
for (WebElement webElement : liElementList) {
// Based on the webElement perform operation
wd.findElement(By.xpath(".//*[@id='horizontalTabAffiliate']/ul/li[1]/a")).click();
System.out.println(wd.getCurrentUrl());
}
}
}
}
<li class="resp-tab-item" aria-controls="tab_item-1" role="tab">
<a class="js-tab-list js-tab-1" data-source="https://www.jdoqocy.com/click-8111003-11553823?url=p;ft=1" data-no="1" data-ga="0" target="iframe_1">
<img src="/themes/centralization/images/partners-tab-logo/feed_logo_vrbo.png" alt="VRBO.Com" height="20" width="auto">
</a>
</li>
【问题讨论】:
-
你能说清楚一点吗,你想得到所有在 iframe 中打开的链接吗?或者你想点击链接然后>移动到新标签作为链接打开然后>找到iframe并使用一些元素执行你的操作?
标签: javascript html selenium iframe webdriver