用硒Python 3单击Web表

<tr id="GBPUSD" class="filled" title="Great Britain pound vs US Dollar
Calculation: Forex
Trade: Full access" draggable="true" style="background: rgb(255,255,255);"><td 
id="symbol" class="symbol"><div class="container"><span class="content">
<span class="i down">&nbsp;</span>GBPUSD</span></div></td>
<td id="bid" class="down" style="text-align: right;">
<div class="container"><span class="content">1.28106</span></div></td>
<td id="ask" class="down" style="text-align: right;"><div class="container">
<span class="content">1.28116</span></div></td><td></td></tr>

这是我要使用Selenium Webdriver双击的项目的html代码。

elem = driver.find_element_by_xpath("//tr[@id='GBPUSD']")
    elem.click()
    elem.click()

这是我的python代码,但我不断收到错误消息:

selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: 
Unable to locate an element with the xpath expression //*[@id='symbol']/div] 
because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[@id='symbol']/div]' is not a valid XPath expression.
  (Session info: chrome=78.0.3904.87)

请帮助我:(

busten 回答:用硒Python 3单击Web表

您的代码显示一个XPath,但是您的错误消息显示另一个XPath-您错误消息中的XPath错误(//*[@id='symbol']/div]),应更改为//*[@id='symbol']/div

示例中的代码实际上不是在此处引发错误的代码。

此外,您可以像这样正确双击:

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


// wait for element to exist
elem = WebDriverWait(driver,10).until(
        EC.presence_of_element_located((By.XPATH,"//tr[contains(@title,'Great Britain Pound')]")))

// double click the element
actionChains = ActionChains(driver)
actionChains.double_click(elem).perform()
本文链接:https://www.f2er.com/3144451.html

大家都在问