简体   繁体   English

硒从页面上的元素获取链接

[英]Selenium getting link from an element on page

In my program i am able to find the element and click it, so I know I have the correct element but when trying to get the link text it returns Promise { <pending> } instead of the link, i am using this code as of now 在我的程序中,我能够找到该元素并单击它,所以我知道我有正确的元素,但是当尝试获取链接文本时,它返回Promise { <pending> }而不是链接,所以我在此使用此代码现在

target = driver.wait(until.elementLocated(By.partialLinkText("iptlogin"))).getText();

it is also a hyperlink in an email if that helps 如果有帮助,它也是电子邮件中的超链接

target = driver.wait(until.elementLocated(By.partialLinkText("iptlogin"))).getAttribute("src");

尝试这个:

If you are using a the async js selenium webdriver you have to wait until text is available. 如果您使用的是异步js硒Webdriver,则必须等到文本可用。 Will look like: 看起来像:

driver.wait(until.elementLocated(By.partialLinkText("iptlogin"))).then(function() {
    //... Element is Available in DOM

    driver.findElement(By.partialLinkText("iptlogin")).getAttribute("href").then(function(resolvedLink) {
        //Here the Link is available in Webdriver-Client
         console.log("Link HREF: "+resolvedLink);
    });

    driver.findElement(By.partialLinkText("iptlogin")).getText().then(function(resolvedText) {
        //Here the Text is available in Webdriver-Client
         console.log("Link Text: "+resolvedText);
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM