Robot Framework for loop - selector always returning same element - selenium

I have an unordered list, from which I need to get the title from each element.
li class="chart-flyout-option" ng-repeat="option in filteredOptions = ($ctrl.options | filter: { value: $ctrl.filterText })" ng-class="{'chart-flyout-option-selected': option.key == $ctrl.selectedOption.key}"><a class="chart-flyout-link" ng-bind-html="option.value | highlight:$ctrl.filterText" title="HERE IS TITLE 1" ng-click="$ctrl.select(option.key, $event)" data-key="126">HERE IS TITLE 1</a></li>
Next element would be similar, but assume - HERE IS TITLE 2
I have a for loop, which looks like this:
Get Flyout Entry Child Links
${numflyoutentries}= Get Number Chart Flyout Entries
${numflyoutentries}= Evaluate ${numflyoutentries} + ${1}
: FOR ${entry} IN RANGE 1 ${numflyoutentries}
\ ${label}= Get Text class:chart-flyout-link
\ Log ${label}
However this only ever returns the text "HERE IS TITLE 1".
Why doesn't my selector increment?

Related

Long live for a selenium script?

Let's say I have a webpage that I need to have some selenium script to automate the UI testing. This page has a list of sections, in the order of "Section A", "Section B", "Section C", etc. Here is my piece of code to automate the steps on "Section B" area testing.
by = By.CSS_SELECTOR
dropdown_in_SectionB = "#app > div.app > div > div > div.content > div:nth-child(2) > div > div:nth-child(7) > ..."
WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((by, target))).click()
Unfortunately, I can not find a XPATH value for this "drowdown_in_SectionB" area, and I have to use css_selector value here. And it works ok for this second.
But later on, this page has been updated, the updated page now contains "Section A", "SectionX", "Section B", "Section C", in such order. And my above script is broken, as the css_selector value of drowpdown_in_Section becomes:
dropdown_in_SectionB = #app > div.app > div > div > div.content > div:nth-child(2) > div > div:nth-child(8) > ..."
So I have to update the script to have it back to working, which is annoyed.
My question is how may I find a way that the script is smart enough to locate the location in its "css_selector" value, however the change is ?
If it was of XPATH value, I can easily have it solved, as I have other clues to trace the dropdown area in Section, but how this can be done in case of css_selector value ???
Thanks,
Jack

Gravityforms - Add category mid-radio-button field

I am populating Gravityforms fields using the functions.php from my template and it works like a charm, but I have one field that is ... a challenge. I have been able to populate the choices from my database just fine, but with the functions.php I cannot control the content of the display area of the field so that I can, for example, add a title or header for each category. Is there a way to programattically adjust the display here's an example of what im hoping to accomplish
RadioButton Choice (Field ID 21)
Dark Colors (category title)
maroon (choice 1)
navy blue (choice 2)
black (Choice 3)
Standard Colors (Category Title)
Red (choice 4)
blue (choice 5)
gray (Choice 6)
Light Colors )Category Title)
pink (choice 7)
sky blue (choice 8)
white (Choice 9)
I am just looking for a way to add the category title between the choices. My DB Query has the categories as part of the response, but the only option I have to populate choices to to feed an array.
I have seen where I can add additional Gravityform fields and have them controlled by the same "single select" radio button option, but the categories involved change based on the DB query I call to dynamically populate the choices and could range from 1 category to 10, which will not have correlating fields in the form itself, as this is all under a single radio-button field.
Any thoughts would be appreciated.
I was able to use the link I posted in my comment to provide a solution. As part of my "choices"
here is the function for the Pre-Render to populate choices. In this case I am populating a radio-button field with product images instead of default radio buttons
add_filter('gform_pre_render_1', 'populate_choices');
function populate_choices($form) {
global $wpdb;
// Now to get a list of the products I want to include on this radio-button
$dataQ = "
SELECT category, product_id, product_name
FROM product_table
WHERE product_type = 'whatever I am looking for'
ORDER BY category, product_name ASC
";
$dataR = $wpdb->get_results($dataQ);
$dataList = array();
// get current protocol to use in Product Images
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
// Rebuild URL for use with product image graphics
$productImageUrl = $protocol.$_SERVER['HTTP_HOST'].'/wp-content/product_images/';
// Generate list of choices for the radio-button, along with category headers
foreach ($form['fields'] as $field) {
if ($field->id == '32') { // 32 My specific radio-button field
$category = "";
foreach ($dataR as $data) {
if ($category != $data->category) {
// If I hit a new category, add the "header" item to the "choices" list with a unique search item to identify it, in this case "###"
$category = $data->category;
$dataList[] = array(
'text' => '#'.$category."#",
'value' => ''
);
}
$productImage = str_replace(" ","",strtolower($data->product_name)).".jpg";
$productID = $data->product_id;
$dataList[] = array(
'text' => $data->product_name,
'value' => $productID,
'isSelected' => false,
'price' => '0.00',
'imageChoices_image' => $productImagehUrl.$productImage
);
}
$field->choices = $dataList;
}
}
}
I then added a specific field modifier to update the "#category#" choice elements with html to make the category names show up.
// numbers after filter = "1" for form ID 1, "32" for field ID 32
add_filter('gform_field_choice_markup_pre_render_1_32', function( $choice_markup, $choice) {
if ( strpos( $choice['text'], '#' ) === 0 ) {
$categoryName = str_replace("#","",$choice['text']);
$choice_markup = '
<li style="width:100%;text-align:left;">
<span style="color:#000000;font-weight:bold;font-size:18px;">
<br>
'.$categoryName.'
</span>
</li>
';
}
return $choice_markup;
}, 10, 2);

Extracting data from div tag

so im scraping data from a website and it has some data in its div tag
like this :
<div class="search-result__title">\nDonald Duck <span>\xa0|\xa0</span>\n<span class="city state" data-city="city, TX;city, TX;city, TX;city, TX" data-state="TX">STATENAME, CITYNAME\n</span>\n</div>,
I want to scrape "Donald Duck" part and state and city name after rel="nofollow"
the site contains a lot of data so name and state are different
the code that i have written is
div = soup.find_all('div', {'class':'search-result__title'})
print (div.string)
this gives me a error
"ResultSet object has no attribute '%s'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?" % key
first, use .text. Second, find_all() will return a list of elements. You need to specify the index value with either: print (div[0].text), or since you will probably have more than 1 element, just iterate through them
from bs4 import BeautifulSoup
html = '''<div class="search-result__title">\nDonald Duck <span>\xa0|\xa0</span>\n<span class="city state" data-city="city, TX;city, TX;city, TX;city, TX" data-state="TX">STATENAME, CITYNAME\n</span>\n</div>'''
soup = BeautifulSoup(html, 'html.parser')
div = soup.find_all('div', {'class':'search-result__title'})
print (div[0].text)
#OR
for each in div:
print (each.text)

Having trouble with findAll statements

Trying to dig into html to get color.
color = soup.find_all('a', {'class' : 'logsss_event_cl itemAttr current'})
print(color)
What I get is:
[<a class="logsss_event_cl itemAttr current" data-logsss-const-value="{'x': 'change_color'}" data-value="WHITE" href="javascript:void(0)" title="**WHITE**"><img src="https://gloimg.rglcdn.com/rosegal/pdm-product-pic/Clothing/2019/04/24thumb-img/1556072536277922126.jpg"/></a>, <a class="logsss_event_cl itemAttr current" data-logsss-const-value="{'x': 'change_size'}" data-value="3X" href="javascript:void(0)" title="3X">3X</a>] href
What I want is "white"
Your search is returning all values for links with the class logsss_event_cl itemAttr current. If you want the text value, you can accomplish that using the following code:
# first, get all values for colo
color_all = soup.find_all('a', {'class' : 'logsss_event_cl itemAttr current'})
# Next, only get text
color_text = [x.get('title') for x in color_all]

How to put contrasting information into a CGridView column based on a condition?

I'm looking into showing/hiding specific column data on a CGridView widget for the Wii Framework.
I have a CButtonColumn which contains 3 buttons. However, on certain conditions, I want to display something different for a particular row.
I have 3 different conditions which determin what gets displayed for particular row.
The following illustrates what I want to do:
| 1 | Title A | [hide][view][update] <-- if (condition == 'a')
| 2 | Title B | [hide][view][update] <-- if (condition == 'a')
| 3 | Title C | display text or link or button <-- if (condition == 'b')
| 4 | Title D | display alternative buttons <-- if (condition == 'c')
What is my best approach to take here?
I can't use 'visible'=> $model->processingStatus != "processed" on the column because this will remove the whole column. I need to target each row insatead.
Should I use the 'visible' parameter on each individual button? I have tried this using the commented out code below but it breaks the page.
FYI: I have successfully tried the 'visible' parameter on the CButtonColumn itself, but its not what I need. Plus not sure which row's status it is reading.
Or should I add a function to the controller? Have it do the if/else statements and return back what is to be displayed. How would this work?
Here is my code:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'my-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'name'=>'myid',
'header'=>'ID',
),
'Title',
array(
'class'=>'CButtonColumn',
'visible'=> $model->status != "done",
'template'=>'{hide}{view}{update}',
'buttons'=>array(
'hide'=>array(
'label'=>'Hide', //Text label of the button.
'imageUrl'=>Yii::app()->request->baseUrl . '/img/icons/bulb-off.png' //Image URL of the button.
//'click'=>'function(){alert("Toggle Hide!");}', //A JS function to be invoked when the button is clicked.
//'options'=>array(), //HTML options for the button tag.
//'url'=>'javascript:void(0)', //A PHP expression for generating the URL of the button.
//'visible'=> $model->status == "done", //A PHP expression for determining whether the button is visible.
),
'view'=>array(
//Text label of the button.
'label'=>'View',
//Image URL of the button.
'imageUrl'=>Yii::app()->request->baseUrl . '/img/icons/view-record.png'
),
'update'=>array(
'label'=>'Update/Edit',
'imageUrl'=>Yii::app()->request->baseUrl . '/img/icons/edit-pencil.png',
'url'=>'Yii::app()->createUrl("metadataandchapters/create?bookid=" . $data->bookid)',
)
)
)
)
)); ?>
Hope I am making good enough sense here!
You should use visible button option, but it should be a PHP expression string, e.g. :
'visible'=> '$data->status == "done"',
http://www.yiiframework.com/doc/api/1.1/CButtonColumn#buttons-detail
Extend CButtonColumn with your own class, then you should be able to change this function to whatever you need to render or hide buttons or do any changes you want.
/**
* Renders a link button.
* #param string $id the ID of the button
* #param array $button the button configuration which may contain 'label', 'url', 'data-icon', 'imageUrl' and 'options' elements.
* #param integer $row the row number (zero-based)
* #param mixed $data the data object associated with the row
*/
protected function renderButton($id, $button, $row, $data)
More details about the function http://www.yiiframework.com/doc/api/1.1/CButtonColumn#renderButton-detail