Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
硒+;python如何单击此链接?_Python_Selenium_Selenium Webdriver - Fatal编程技术网

硒+;python如何单击此链接?

硒+;python如何单击此链接?,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,请告诉我,如何使用Python+Selenium单击此链接 HTML: 脚本(但不工作): 以下是你问题的答案: 首先,您需要切换到帧: from selenium import webdriver from selenium.webdriver.firefox.firefox_binary import FirefoxBinary import time binary = FirefoxBinary('C:\\Program Files\\Mozilla Firefox\\firefox.

请告诉我,如何使用Python+Selenium单击此链接

HTML:

脚本(但不工作):


以下是你问题的答案:

首先,您需要切换到

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
import time

binary = FirefoxBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary, executable_path="C:\\Utility\\BrowserDrivers\\geckodriver.exe")
driver.get('http://rutracker.ignn.ru')
time.sleep(5)
driver.switch_to.frame(driver.find_element_by_xpath("//iframe[contains(@src,'tmozs.com/jsonp.php')]"))
time.sleep(5)
driver.find_element_by_xpath("//div[@class='feed-inner']/div[@class='feed-cell'][1]/a[@class='feed-cell-inner' and contains(@href,'http://tmozs.com/info.php?')]").click()
time.sleep(5)
driver.quit()

PS:您可以考虑在<元素> >代码>显式> < /代码> <强>,而不是<代码>时间。


如果这能回答您的问题,请告诉我。

您可以尝试以下XPATH:-
//div[@class=“feed cell”]/a[@class=“feed cell internal”]


//a[@class=“提要单元格内部”或包含(@href,”http://tmozs.com“”]

有一个解决当前问题的方法issue@Andersson哪一个?@DebanjanB,中提供的链接comment@Andersson明白了:)我没有看到前面的问题。感谢文件“c:\Python27\lib\site packages\selenium\webdriver\remote\errorhandler.py”,第192行,在check\u response raise exception\u class(message,screen,stacktrace)selenium.common.exceptions.NoSuchElementException:message:无法找到元素://a[@class='feed-cell-inner'并包含(@href,@AndrewF.检查我的最新答案,让我知道它是否对你有效。德班詹B是的!!它有效!!非常感谢!祝你有一个愉快的一天和周末!@Andrew F.好消息!!!很高兴能够帮助你。如果答案对你有用,请投票。谢谢班詹B你好朋友!我尝试使用此脚本在其他网站上单击此链接。但没有错误不点击=(ds.ignn.ruCan您可以试试这个//div/a[@class=“feed cell-inner”和@herf='xyz.com']
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
import time

binary = FirefoxBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary, executable_path="C:\\Utility\\BrowserDrivers\\geckodriver.exe")
driver.get('http://rutracker.ignn.ru')
time.sleep(5)
driver.switch_to.frame(driver.find_element_by_xpath("//iframe[contains(@src,'tmozs.com/jsonp.php')]"))
time.sleep(5)
driver.find_element_by_xpath("//div[@class='feed-inner']/div[@class='feed-cell'][1]/a[@class='feed-cell-inner' and contains(@href,'http://tmozs.com/info.php?')]").click()
time.sleep(5)
driver.quit()