[英]Problem with selenium, closing the main window when opening the popup. How get href from this link?
My problem is that when you click on the link, a pop-up window opens, but when working with selenium, it opens, but closes the main window.我的问题是,当您单击链接时,会打开一个弹出窗口,但是在使用 selenium 时,它会打开,但会关闭主窗口。 I open the link using
.click()
我使用
.click()
打开链接
Here's the html:这是html:
<a class="do do-task btn btn-sm btn-primary btn-block" href="javascript:;"
data-task-id="13054765" data-do-class="do-task"
data-getcomment-href="/tasks/getcomment/" data-check-count="0"
data-max-check-count="2" data-point-text="10 points">
<i class="far FA-star"></I> 10 points</a>
Function for click:点击功能:
driver = webdriver.Chrome('chromedriver.exe')
def click_tasks():
tasks = driver.find_elements_by_class_name('btn-block')[7:]
print(tasks[0].text)
tasks[0].click()
You can find out the href
, but I don't know how.你可以找到
href
,但我不知道如何。
Help me find out how to get href
or make the main window not close when you open the pop-up window.帮助我了解如何在打开弹出窗口时获取
href
或使主窗口不关闭。 I will be grateful.我会很感激。
假设您已经初始化了一个像 driver = webdriver.Chrome() 这样的驱动程序,根据您发布的html
获取href
的一种方法是:
your_href=driver.find_element_by_class_name('do do-task btn btn-sm btn-primary btn-block').get_property('href')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.