I'm using selenium and chrome webdriver with python.
I'm trying to store 'href' inside a variable ('link' for this example) and open it in a new tab.
i know how to open a dedicated website in a new tab using this way:
driver.execute_script("window.open('http://www.example.com', 'newtab')")
but using windows.open script accepts only direct text(as far as i know) and not variables.
Here is the code:
link = driver.find_element_by_class_name('asset-content').find_element_by_xpath(".//a[@class='mr-2']").get_attribute("href") #assigning 'href' into link variable. works great.
driver.execute_script("window.open(link, 'newtab')") #trying to open 'link' in a new tab
The error:
unknown error: link is not defined
Any other way i can open 'link' variable in a new tab?