I am unable to access this menu in selenium the web element doesn't appear in inspector until manually done
<a id="cke_3275" class="cke_menubutton cke_menubutton__table cke_menubutton_off cke_menubutton__table" href="javascript:void('Table Properties')" title="Table Properties" tabindex="-1" _cke_focus="1" hidefocus="true" role="menuitem" aria-haspopup="false" aria-disabled="false" onmouseover="CKEDITOR.tools.callFunction(666,5);" onmouseout="CKEDITOR.tools.callFunction(667,5);" onclick="CKEDITOR.tools.callFunction(668,5); return false;">
<span class="cke_menubutton_inner">
<span class="cke_menubutton_icon">
<span class="cke_button_icon cke_button__table_icon" style="background-image:url(https://lms.testbook.com/vendor/ckeditor/plugins/icons.png?t=E6FD);background-position:0 -1896px;background-size:auto;">
</span>
</span>
<span class="cke_menubutton_label">
Table Properties
</span>
</span>
</a>
I tried accessing parent, click and actions.perform() nothing seems to work.
When i hover over the menu contents i see javascript:void('contentname'), i pasted this in the inspector and found the web element.
iframe=WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "/html/body/iframe")))
driver.switch_to.frame(iframe)
driver.find_element_by_tagname("a")
switch to iframe and then add rest of the code
driver.switch_to.default_content()
you need to switch to default content after you are done with the element and want to interact with an element outside the iframe
Related
I have a problem,
when I look for the id of an xpath it changes every time I enter the web
how can i use selenium webdriver python
browser.find_element(By.ID,)
if the id changes every time I consult it
first
<span data-dojo-attach-point="containerNode,focusNode"
class="tabLabel" role="tab" tabindex="0"
id="icm_widget_SelectorTabContainer_0_tablist_dcf42e75-1d03-4acd-878c-722cbc8e74ec"
name="icm_widget_SelectorTabContainer_0_tablist_dcf42e75-1d03-4acd-878c-722cbc8e74ec"
aria-disabled="false"
title=""
style="user-select: none;"
aria-selected="true">Search</span>
second
<span data-dojo-attach-point="containerNode,focusNode"
class="tabLabel"
role="tab"
tabindex="0"
id="icm_widget_SelectorTabContainer_0_tablist_c9ba5042-90d2-4932-8c2d-762a1dd39982"
name="icm_widget_SelectorTabContainer_0_tablist_c9ba5042-90d2-4932-8c2d-762a1dd39982"
aria-disabled="false"
title=""
style="user-select: none;"
aria-selected="true">Search</span>
try with
browser.find_element(By.XPATH
browser.find_element(By.ID
browser.find_element(By.NAME
same problem, the id changes
Try to use below xpath
browser.find_element(By.XPATH(//span[contains(#id, 'icm_widget_SelectorTabContainer') and text()='Search']);
In case the first part of the id is unique and stable as it seems to be, you can use XPath or CSS Selector to locate this element.
XPath:
browser.find_element(By.XPATH, "//span[contains(#id,'icm_widget_SelectorTabContainer_0_tablist')]")
CSS Selector:
browser.find_element(By.CSS_SELECTOR, "span[id*='icm_widget_SelectorTabContainer_0_tablist']")
I'm doing some exercises with selenium, trying to scrape a few pages on facebook.
However, I'm not able to find the "Home" button link element to keep going. This on the left menu in any user's profile.
From what I'm seeing in the page code, the link is here:
<div class="_2yaa" data-key="tab_home">
<a class="_2yau" data-endpoint="/seudogshow/?ref=page_internal" href="/seudogshow/?ref=page_internal">
<span class="_2yav">Home</span>
<span class="img _55ym _55yn _55yo _2wwb" aria-busy="true" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuetext="Loading..."></span>
</a>
</div>
How would you guys go about clicking this button?
I tried with something like this:
driver.find_element_by_xpath("//a[contains(text(), 'Home')]").click()
or
wait.until(EC.element_to_be_clickable((By.XPATH, "//a[contains(text(), 'Home')]"))).click()
But I'm clearly doing it wrong.
The element you are trying to click has a span tag, not a. Try the following:
driver.find_element_by_xpath("//span[contains(text(), 'Home')]").click()
<li id="b43d980c-53bb-4892-8f32-5ae8ebd9026e" class="">
<input type="button">
<span>Male</span>
</li>
How can I locate this and then click on it?
Text() attribute in xpath locator should do the trick to find the span:
driver.find_element(By.XPATH("//span[text()='Male']"))
Want to grab the input before?
driver.find_element(By.XPATH("//span[text()='Male']/preceding-sibling::input"))
how do i click on the href link: href="/in/x-y-07976b159/" using selenium?
<a data-control-id="SOR2sXWgS8mDhCUEgFncpQ==" data-control-name="search_srp_result" href="/in/x-y-
07976b159/" id="ember1502" class="search-result__result-link ember-view"> <h3 id="ember1503"
class="actor-name-with-distance search-result__title single-line-truncate ember-view"> <span
class="name-and-icon"><span class="name-and-distance">
<span class="name actor-name">x y</span>
<span data-test-distance-badge="" id="ember1504" class="distance-badge separator ember-view">
<span class="visually-hidden">
1st degree connection
</span>
<span class="dist-value">1st</span>
</span>
</span><!----></span>
</h3>
</a>
You can click it with the help of below command.
driver.find_elements_by_xpath("//a[#id='ember1502']").click();
Where driver is the web driver instance.
You can do it both ways.
1) Find this element (eg. by id) and invoke method .click() on it.
2) Go to page (using driver.get(youcurrenturl + yourextracted href))
Another way of doing using find_element_by_idmethod.
driver = webdriver.Chrome()
driver.get('http://www.YourUrl.com')
driver.find_element_by_id('ember1502').click()
I have an element that requires a double_click().perform() action. It works great in Firefox, but doesn't in Chrome. A single click displays a menu, but a double click takes you to a directory. Here is my python/selenium step:
(webdriver.ActionChains(self.browser)).double_click(self.browser.find_element_by_id('nav-link-shopall')).perform()
The error message returns that the text I'm wanting to verify exists does not exist. Which is true if the double_click().perform() doesn't do its job.
I'm using Python 2.7.8 and Selenium 2.45.0.
I'm using Amazon.com as an example because the behavior is the same as the proprietary code I am testing. So here is the HTML code I'm attempting to click:
<div class="nav-left">
<div id="nav-shop">
<a href="/gp/site-directory/ref=nav_shopall_btn" class="nav-a nav-a-2" data-nav-tabindex="15" id="nav-link-shopall" tabindex="1">
<span class="nav-line-1">Shop by</span>
<span class="nav-line-2">"Department"
<span class="nav-icon nav-arrow" style="visibility:visible;"></span>
</span>
</a>
</div>
</div>
Try this:
variable = self.browser.find_element_by_id('nav-link-shopall')
actions = ActionChains(driver)
actions.move_to_element(variable)
actions.double_click(variable)
actions.perform()
You should use move to element.