Javascript 如何在python中使用selenium驱动程序在don';我不知道锚定标记中的文本

Javascript 如何在python中使用selenium驱动程序在don';我不知道锚定标记中的文本,javascript,jquery,python,selenium,xpath,Javascript,Jquery,Python,Selenium,Xpath,我使用selenium+phantomJS+scrapy来删除javascript内容。我想在加载javascript内容后单击表中的链接。但最重要的是,随着输入内容的不同,我想点击的链接也发生了变化 然后我想使用xpath来定位链接,但失败了。下面是我编写的html元素和xpath <div class="results searchResults" style="display: block;”> <table cellspacing="0" id="resultG

我使用
selenium+phantomJS+scrapy
来删除javascript内容。我想在加载javascript内容后单击表中的链接。但最重要的是,随着输入内容的不同,我想点击的链接也发生了变化

然后我想使用xpath来定位链接,但失败了。下面是我编写的html元素和xpath

<div class="results searchResults" style="display: block;”>
    <table cellspacing="0" id="resultGroup">
        <colgroup>
            <col width="4.216%">
            <col width="43.13%">
            <col width="52.65%">
        </colgroup>
        <tbody>
            <tr class="">
                <td class="selector">
                    <a href="#" id="c_2441797" title="Apple Inc." class="checkbox unchecked">&nbsp;</a>
                </td>
                <td class="name">
                    <div>
                        <a href="#!search/profile/company?companyId=2441797&amp;targetid=profile" class="companyResultsName">Apple Inc.</a>
                        <a href="http://www.google.com/finance?client=ob&amp;q=NASDAQ: AAPL" rel="external" target="_blank">(NASDAQ: AAPL)</a>
                    </div>

如果您的元素是由
JavaScript
动态生成的,您应该等待它出现在
DOM
中:

 from selenium.webdriver.common.by import By
 from selenium.webdriver.support.ui import WebDriverWait
 from selenium.webdriver.support import expected_conditions as EC

 link = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CLASS_NAME, "companyResultsName")))
 link.click()

你能添加
html
而不是图像吗。您的
xpath
似乎不正确。请尝试xpath
//a[@class='companyResultsName'][contains(text(),'Apple Inc.])]
@Narendra Rajput我已将照片更改为
html
@narendrajput我尝试了您的xpath,但终端输出错误
NoSuchElementException:Message:{“errorMessage”:“找不到带有xpath的元素”//a[@class='companyResultsName'][包含(text(),'Apple Inc.')”,
确保您的元素不在
iframe
下,如果是,则必须切换到frame。如果不是,则使用
explicit wait
conditionsman!您太棒了!我不知道为什么我会遵循您的建议,然后我可以单击链接!非常感谢。顺便说一句,如果我想单击与sam相关的第二个链接e班,我该怎么办?