Python 点击锚标签的代码
Python code to click on anchor tag
我正在编写 python 代码来自动化网页。
我需要点击播放按钮来播放录音。但是我无法通过代码这样做。
检查元素给我这个 - 'play' 的外部 HTML :
<div class="play">
<a id="sm_1855464769" class="sm2_button" href="#"> </a>
</div>
检查元素给我这个 - 'play' 的 Xpath :
//*[@id="recording_1855464769"]/div/div/div[8]
我写的python代码是:
element = WebDriverWait(self.driver, 15).until(EC.presence_of_element_located(EC.find_element_by_xpath("//*[@id='recording_1855464769']/div/div/div[8]"))
element.click()
我在终端中收到的错误消息:
element = WebDriverWait(self.driver, 15).until(EC.presence_of_element_located(EC.find_element_by_xpath("//*[@id='recording_1855464769']/div/div/div[8]")))
AttributeError: 'module' object has no attribute 'find_element_by_xpath'
我需要点击锚标签才能播放音频。我怎样才能做到这一点 ??请帮助..
您需要使用 By
。将 EC.find_element_by_xpath
替换为 By.XPATH
.
from selenium.webdriver.common.by import By
element = WebDriverWait(self.driver, 15).until(EC.presence_of_element_located
(By.XPATH("//*[@id='recording_1855464769']/div/div/div[8]"))
我正在编写 python 代码来自动化网页。 我需要点击播放按钮来播放录音。但是我无法通过代码这样做。
检查元素给我这个 - 'play' 的外部 HTML :
<div class="play">
<a id="sm_1855464769" class="sm2_button" href="#"> </a>
</div>
检查元素给我这个 - 'play' 的 Xpath :
//*[@id="recording_1855464769"]/div/div/div[8]
我写的python代码是:
element = WebDriverWait(self.driver, 15).until(EC.presence_of_element_located(EC.find_element_by_xpath("//*[@id='recording_1855464769']/div/div/div[8]"))
element.click()
我在终端中收到的错误消息:
element = WebDriverWait(self.driver, 15).until(EC.presence_of_element_located(EC.find_element_by_xpath("//*[@id='recording_1855464769']/div/div/div[8]")))
AttributeError: 'module' object has no attribute 'find_element_by_xpath'
我需要点击锚标签才能播放音频。我怎样才能做到这一点 ??请帮助..
您需要使用 By
。将 EC.find_element_by_xpath
替换为 By.XPATH
.
from selenium.webdriver.common.by import By
element = WebDriverWait(self.driver, 15).until(EC.presence_of_element_located
(By.XPATH("//*[@id='recording_1855464769']/div/div/div[8]"))