Dash App Table Not allowing links to be clickable. They appear to be clickable links when I hover my mouse over the title but do not do anything when I click on them.
The following is a function I am using to build the the table:
def build_rows(images,titles,author,category,price,link):
"""
builds a table body. All parameters expect a list type
"""
rows = []
for x in range(len(titles)):
rows.append(html.Tr([html.Img(src=images[x], height="100px"),
html.Td(dcc.Link(titles[x], href=link[x])), # <--- This the problem
html.Td(author[x]),
html.Td(category[x]),
html.Td(price[x]),
html.Td(link[x])]))
table_body = [html.Tbody(rows)]
return table_body
Thank you for your help.
NOTE: I always upvote and select a correct answer when applicable
If you just want a regular anchor tag with an href, then you want to use html.A (ie import dash_html_components as html) rather than dcc.Link.
The dcc.Link component is for use with the dcc.Location component, and allows to to create single page applications, by hooking up a callback function to the value of the current URL, returning different layout fragments into a specific container element. If this is what you're trying to do, see the docs on how to use the Location component.
Related
Im trying to interact with a js rendered page. Essentially this is a free widget from tradingview; however, the color of the lines is not something I can change. (yes there is an override, however, it only affects 1 line) I need to be able to change 2 lines.
Trading View Advanced Chart Widget Constructor
Can anyone tell me if this is possible with a puppeteer? How can I get XPath for an element which is generated by JS? View source and developer tools do not provide any xpaths to the elements.
I could scroll down or up a whole web page but I am having trouble in scrolling a particular div element within the webpage
The thing is when I open a webpage like whatsapp web and within a particular chat containing the messages(which is particular div element),I want to scrape all the messages from the beginning of the chat ,but I could only scrape the messages which is in the view (the last few messages),So I want to scroll that particular div element to the top of the chat to scrape all the messages.
Can someone help me with this thing in PYTHON.
Thank you.
Yes, there are multiple ways using which you could scroll to particular element
By using the move_to_element()
element = driver.find_element_by_xpath("_element_")
action = ActionChains(driver)
action.move_to_element(element).perform()
By scrollIntoView()
element = driver.find_element_by_xpath("_element_")
driver.execute_script("arguments[0].scrollIntoView(true);", element)
For reference check here
It is possible.
Let's say the element you need to scroll inside is div_el, it's locator is xpath_locator the code will be like this:
div_locator = "xpath_locator"
div_el = driver.find_element_by_xpath(div_locator)
driver.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", div_el)
See more here
I am a little bit new to programming but python really made get into it. I am trying to create a programm that automatically checks for updates in a website. I've successfully implemented the neccessary code to call the page of enrollment but yet there is one element that cannot be located. Since I have to do it for multiple courses and iterate throught them there is no specific id, I've tried to find it by title but also this didn't work.
Is there a way you can locate the button with the title "enroll".
I've tried
driver.find_element_by_xpath("//a\[#title ='enroll']").click()
but this didn't work and I always get
NoSuchElement
error.
The XPATH for the button is simply: //*\[#id="id572"\]
Here is the part of the HTML code:
From the screenshot of HTML code you provided, the element is <button>, not <a>.
Try this xpath expression //button[#title='enroll']
This should do it if it's not in any iframes. Just grab the button whose title is enroll and click. Your css selector was an a tag and it might get id dynamically.
driver.find_element_by_css_selector("button[title ='enroll']").click()
Issue : - Unable to detect the iframe and switch to iframe as the iframe id and name dynamically changes at each time it loads but the src remain the same.
Unable to identify the xpath as well. Found iframe tag using driver.find_element_by_tagname("iframe") but cant view the tag <iframe> in the HTML of the page source. Therefore unable to find the xpath by right click and iframe tag.
Already tried to find the number of frame size using 'frame.size' but since its not callable, it provide answer in dict which is 'height:0,weight:0'
Require to switch to this iframe and work with the element inside the iframe which is to
1) enter text field into the iframe
2) select radio button in the iframe
Unable to select element after switch to iframe
Screenshot of the code
enter image description here
By default, each frame is assigned an integer number. So you can always do:
driver.switchTo().frame(0)
or
driver.switchTo().frame(1)
You can wait until frame to be loaded as given below.
wait = WebDriverWait(driver, 300)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,'//iframe')))
I was able to answer this, by determining the number of iframe. I've used 'find_element's'_by_tagname('iframe') instead of find_element_bytagname('iframe') which was able to find more than 1 iframe if exist in the page source.
This provides me total 3 iframe tag. Then i proceed to loop into the iframe and find the attribute of the each iframe such as id,name and src.
Then i noticed one of the iframe src, refers to the web address that has the element which i was looking for. Then i proceed to switch to that particular frame using if statement.
Once switch to the iframe, i proceed to get the element.
This solved on how to switch between frame using python-selenium and detect element upon switch the frame.
The key here is to detect on which frame does the element exist within and able to switch to that frame. The frame could be either nested within one frame or list of frame in the main window.
Upon detect and switch the frame. Then would be able to locate the element.
This solves the challenges
This is the website of skyscanner. After selecting flight I want to click on every 'Select button'(for $687) and then go to next page. On next page I want to click down arrow for outbound flight. Then I again I want to click select button ($715) and the again outbound flight arrow. So it goes in loop for all possible searches on all the pages possible.
This is how Downward arrow on next page is
Here is the code I have written so far
:
driver = webdriver.Chrome( )
driver.get('https://www.skyscanner.com/transport/flights/nyca/lax/170717/170718/airfares-from-new-york-to-los-angeles-international-in-july-2017.html?adults=1&children=0&adultsv2=1&childrenv2=&infants=0&cabinclass=economy&rtn=1&preferdirects=false&outboundaltsenabled=false&inboundaltsenabled=false&ref=home#results')
while True:
items=driver.find_element_by_class_name("fss-bpk-button expand-cba select-action")
for i, item in enumerate(items):
driver.find_element_by_class_name("fss-bpk-button expand-cba select-action").click()
for j, item2 in item
driver.find_element_by_class_name("leg-summary-container clearfix").click()
I also tried following but none worked:
links = [link.get_attribute('href') for link in driver.find_element_by_class_name("fss-bpk-button expand-cba select-action")]
for link in links:
driver.get(link)
Your second code should work after some changes:
links = [link.get_attribute('href') for link in driver.find_elements_by_css_selector("a.fss-bpk-button.expand-cba.select-action")]
Note that
To get list of elements you should use find_elements_...() instead of find_element_...()
Compound class names not allowed, so you might use search by CSS selector or XPath instead of search by class name if you want to use multiple class names to locate required elements